-
Notifications
You must be signed in to change notification settings - Fork 24
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
Accelerate insertion of large number of elements #149
Accelerate insertion of large number of elements #149
Conversation
Codecov ReportAll modified lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #149 +/- ##
==========================================
+ Coverage 77.75% 77.77% +0.01%
==========================================
Files 470 470
Lines 50331 50332 +1
==========================================
+ Hits 39136 39144 +8
+ Misses 11195 11188 -7
☔ View full report in Codecov by Sentry. |
The change seems naively safe. My question is... why not having the registered objects being a |
The variable previousVersion stored an array of the keys belonging to the dictionary undoMap. This last line regenerated this array for no reason, since previousVersion is a local variable and is not mutated inside the message's body.
…uctures. This then forces the previousVersion array to be recreated. I added as Set to it as well.
This change does not modify any write order. When iterating over I made another commit, because the final line of the block recreates the array with keys from undoMap so I made it a set as well. I see your point, we could avoid regenerating previousVersion if we update it while adding new keys to the undo map for recursive structures. Let me try that in another PR. |
…reating the set again from all the keys.
the last commit improves by adding new elements to the previousVersions set instead of creating a whole new set. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
ObjectTransaction>>registeredObjectsDo: iterates over a collection and checks if the element belongs to another collection. This verification uses Array>>includes: which traverses the array until an element is found. For a small number of elements this approach is OK. but when the number of elements increases, then the verification algorithm is O(n^2).
Converting the search array into a set makes the behavior almost linear again for large sizes and has no impact on smaller sized batches.
See time improvement after change: