Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(core): use batch inserts in UoW (postgres & mongodb) #865

Merged
merged 1 commit into from
Sep 24, 2020

Conversation

B4nan
Copy link
Member

@B4nan B4nan commented Sep 24, 2020

UoW will now batch all inserts statements if the driver supports returning all of their
PKs back (so postgres and mongodb currently).

This also changes how Collection.contains() was implemented - it did a linear check
on all values, comparing by the PK for persisted entities. This took extreme amount of
time with huge collections, just to add to a collection 1000 times, it was as slow as
1s for this, without persisting anything.

Now the collection items are stored as Set, and contains method does a simple identity
lookup (set.has(entity)). Another issue that slowed it down was the array like index support,
where we are able to use coll[0] to access the first item in the collection. This was
implemented as a re-assigning of all items to the collection object, which was extremely slow
for large collections. Now when we add to a collection, we only append the last index instead
of reassigning everything.

Closes #732

UoW will now batch all inserts statements if the driver supports returning all of their
PKs back (so postgres and mongodb currently).

This also changes how `Collection.contains()` was implemented - it did a linear check
on all values, comparing by the PK for persisted entities. This took extreme amount of
time with huge collections, just to add to a collection 1000 times, it was as slow as
1s for this, without persisting anything.

Now the collection items are stored as `Set`, and `contains` method does a simple identity
lookup (`set.has(entity)`). Another issue that slowed it down was the array like index support,
where we are able to use `coll[0]` to access the first item in the collection. This was
implemented as a re-assigning of all items to the collection object, which was extremely slow
for large collections. Now when we add to a collection, we only append the last index instead
of reassigning everything.

Closes #732
@B4nan B4nan merged commit 54ad928 into master Sep 24, 2020
@B4nan B4nan deleted the uow-batch-insert branch September 24, 2020 14:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

High memory profile and very slow
1 participant