-
Notifications
You must be signed in to change notification settings - Fork 31.1k
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 array comparison #57619
base: main
Are you sure you want to change the base?
assert,util: improve array comparison #57619
Conversation
Sparse arrays and arrays containing undefined are now compared faster using assert.deepStrictEqual() or util.isDeepStrictEqual().
Review requested:
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #57619 +/- ##
==========================================
- Coverage 90.24% 90.22% -0.02%
==========================================
Files 630 630
Lines 185129 185053 -76
Branches 36238 36214 -24
==========================================
- Hits 167064 166960 -104
- Misses 11045 11055 +10
- Partials 7020 7038 +18
🚀 New features to boost your workflow:
|
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.
it's very surprising to me that checking undefined is faster, especially in the case of getters, but if the benchmarks say it is, so be it :-)
This improves the performance to compare unequal numbers while doing a deep equal comparison. Comparing for NaN is faster by checking `variable !== variable` than by using `Number.isNaN()`.
Sparse arrays and arrays containing undefined are now compared faster using assert.deepStrictEqual() or util.isDeepStrictEqual().
Update: I added another commit that also improves the comparison performance for unequal numbers.
Local benchmark (more configurations and higher iterations to show that even regular arrays improve by ~1%. This should not matter for regular runs, so I kept the benchmark simpler in here):