-
Notifications
You must be signed in to change notification settings - Fork 31.3k
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
assert,util: improve deep object comparison performance #57648
assert,util: improve deep object comparison performance #57648
Conversation
Review requested:
|
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.
looks good, just some thoughts
717c5ac
to
c9b2d34
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #57648 +/- ##
==========================================
+ Coverage 90.24% 90.27% +0.02%
==========================================
Files 630 630
Lines 184990 185129 +139
Branches 36216 36259 +43
==========================================
+ Hits 166948 167116 +168
+ Misses 11003 10984 -19
+ Partials 7039 7029 -10
🚀 New features to boost your workflow:
|
Failed to start CI⚠ Commits were pushed since the last approving review: ⚠ - assert,util: improve deep object comparison performance ⚠ - assert,util: improve deep equal comparison performance ⚠ - assert,util: improve (partial) deep equal comparison performance ⚠ - test: add assert.deepStrictEqual test cases to cover more cases ✘ Refusing to run CI on potentially unsafe PRhttps://github.com/nodejs/node/actions/runs/14264748421 |
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.
Broadly speaking, a lot of these optimizations are very non-obvious, and could use some commentary. That said, the reasons why become clearer on multiple reads, so I'm not going to block on that.
The one about getting the descriptor instead of using ObjectPropertyIsEnumerable still stands though.
This improves the performance for almost all objects when comparing them deeply.
This allows the compiler to inline parts of the code in a way that especially primitives in arrays can be compared faster.
The circular check is now done lazily. That way only users that actually make use of such structures have to do the calculation overhead. It is an initial overhead the very first time it's run to detect the circular structure, while every following call uses the check for circular structures by default. This improves the performance for object comparison significantly. On top of that, this includes an optimised algorithm for sets and maps that contain objects as keys. The tracking is now done in an array and the array size is not changed when elements at the start or at the end of the array is detected. The order of the elements matter, so a reversed key order is now a magnitude faster. Insert sort comparison is also signficantly faster, random order is a tad faster.
ccea4ca
to
75d8fbb
Compare
Landed in e739559 |
This improves the performance for almost all objects when comparing them deeply. PR-URL: nodejs#57648 Reviewed-By: Jordan Harband <[email protected]> Reviewed-By: Bryan English <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]>
This improves the performance for almost all objects when comparing
them deeply significantly.