Skip to content

assert: make comparisons file more performant#57088

Closed
puskin wants to merge 1 commit intonodejs:mainfrom
puskin:comparisons-low-hanging-fruit-performance-improvements
Closed

assert: make comparisons file more performant#57088
puskin wants to merge 1 commit intonodejs:mainfrom
puskin:comparisons-low-hanging-fruit-performance-improvements

Conversation

@puskin
Copy link
Copy Markdown
Contributor

@puskin puskin commented Feb 16, 2025

As part of my ongoing review of the assert codebase, I started examining the comparisons.js file and optimizing some straightforward code that could be further refined for better performance.

Here are the benchmark results for the assert/deepequal-simple-array-and-set.js file:

OLD:

assert/deepequal-simple-array-and-set.js method="deepEqual_Array" strict=1 len=10000 n=500: 8,398.503339673252
assert/deepequal-simple-array-and-set.js method="notDeepEqual_Array" strict=1 len=10000 n=500: 8,365.394964343424
assert/deepequal-simple-array-and-set.js method="deepEqual_Set" strict=1 len=10000 n=500: 14,487.154442975576
assert/deepequal-simple-array-and-set.js method="notDeepEqual_Set" strict=1 len=10000 n=500: 14,514.332017493021

NEW: 

assert/deepequal-simple-array-and-set.js method="deepEqual_Array" strict=1 len=10000 n=500: 8,470.789541116153
assert/deepequal-simple-array-and-set.js method="notDeepEqual_Array" strict=1 len=10000 n=500: 8,443.200479573787
assert/deepequal-simple-array-and-set.js method="deepEqual_Set" strict=1 len=10000 n=500: 8,962.574475856993
assert/deepequal-simple-array-and-set.js method="notDeepEqual_Set" strict=1 len=10000 n=500: 10,943.39339352156

a performance improvement of 25-38% can be noticed in the sets tests

@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. util Issues and PRs related to the built-in util module. labels Feb 16, 2025
@puskin puskin force-pushed the comparisons-low-hanging-fruit-performance-improvements branch from 4caa491 to 5edea40 Compare February 16, 2025 10:20
@codecov
Copy link
Copy Markdown

codecov bot commented Feb 16, 2025

Codecov Report

Attention: Patch coverage is 97.61905% with 1 line in your changes missing coverage. Please review.

Project coverage is 89.09%. Comparing base (1d8593e) to head (5edea40).
Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
lib/internal/util/comparisons.js 97.61% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #57088      +/-   ##
==========================================
- Coverage   89.09%   89.09%   -0.01%     
==========================================
  Files         665      665              
  Lines      193249   193259      +10     
  Branches    37231    37224       -7     
==========================================
+ Hits       172175   172178       +3     
- Misses      13802    13812      +10     
+ Partials     7272     7269       -3     
Files with missing lines Coverage Δ
lib/internal/util/comparisons.js 99.85% <97.61%> (-0.15%) ⬇️

... and 25 files with indirect coverage changes

@puskin puskin changed the title comparisons: make comparisons file more performant assert: make comparisons file more performant Feb 16, 2025
@puskin puskin closed this Feb 16, 2025
@targos targos added the needs-benchmark-ci PR that need a benchmark CI run. label Feb 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-benchmark-ci PR that need a benchmark CI run. needs-ci PRs that need a full CI run. util Issues and PRs related to the built-in util module.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants