Skip to content

assert: avoid excess float array comparisons - #67357

Open
alejandrodev-vn wants to merge 1 commit into
nodejs:mainfrom
alejandrodev-vn:perf/assert-floatarray-length
Open

alejandrodev-vn wants to merge 1 commit into
nodejs:mainfrom
alejandrodev-vn:perf/assert-floatarray-length

Conversation

@alejandrodev-vn

Copy link
Copy Markdown

areSimilarFloatArrays() uses the byte length as the loop bound while
accessing typed array elements by index. For equal arrays, this causes
unnecessary out-of-bounds reads after all elements have been compared.

Use TypedArrayPrototypeGetLength for the length check and loop bound.
The intrinsic getter avoids invoking an own length property.

Add coverage for Float16Array, Float32Array and Float64Array, including
subarrays, empty arrays, unequal lengths and shadowed length getters.
Add a benchmark covering equal arrays and several mismatch scenarios.

Local benchmark results for equal arrays with 5,000 elements:

Type Before (ops/s) After (ops/s) Ratio
Float16Array 12,561 29,195 2.32x
Float32Array 17,774 229,386 12.91x
Float64Array 9,707 232,215 23.92x

These are median throughput results from 12 alternating before/after
runs on an Apple M4 Pro, macOS arm64, using a v28.0.0-pre development
build based on 7ae68bd.
The build loads builtins from disk. These measurements apply to this
microbenchmark and do not measure application throughput.

Validation:

  • make lint
  • make lint-yaml (completed with two comment-spacing warnings)
  • make -j4 test (7,619 passed, 0 failed)

Refs: #51040

Signed-off-by: alejandrodev-vn <huytra264@gmail.com>
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/performance

@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 Nov 9, 2026
@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Welcome to Node.js, and thank you for your first contribution!

Before review, please take a moment to read:

Please make sure every commit is signed off. For a first pull request, GitHub Actions require collaborator approval and Jenkins CI must be started by a collaborator or triager, so an initial wait is normal.

@BridgeAR BridgeAR left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you! Should we also add strict assertions?

@codecov

codecov Bot commented Nov 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.72%. Comparing base (f344e7f) to head (e8b4c0b).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #67357      +/-   ##
==========================================
- Coverage   90.73%   90.72%   -0.01%     
==========================================
  Files         798      798              
  Lines      279993   279994       +1     
  Branches    53866    53862       -4     
==========================================
- Hits       254047   254037      -10     
- Misses      16229    16237       +8     
- Partials     9717     9720       +3     
Files with missing lines Coverage Δ
lib/internal/util/comparisons.js 99.53% <100.00%> (+<0.01%) ⬆️

... and 16 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

4 participants