Skip to content

buffer: use typed arrays for 64-bit BigInt accessors - #67549

Merged
nodejs-github-bot merged 1 commit into
nodejs:mainfrom
gurgunday:perf/buffer-bigint64
Nov 19, 2026
Merged

nodejs-github-bot merged 1 commit into
nodejs:mainfrom
gurgunday:perf/buffer-bigint64

Conversation

@gurgunday

Copy link
Copy Markdown
Member

readBig(U)Int64{LE,BE}() and writeBig(U)Int64{LE,BE}() assembled and split values with BigInt arithmetic, allocating intermediate BigInts on every call. Copy the bytes through BigInt64Array and BigUint64Array views over the existing 8-byte scratch buffer instead, as the double accessors already do

benchmark/buffers/buffer-read.js (30 runs):

type buffer=fast buffer=slow
BigInt64LE +224.26 % *** +226.77 % ***
BigInt64BE +224.66 % *** +222.00 % ***
BigUInt64LE +39.58 % *** +39.66 % ***
BigUInt64BE +39.31 % *** +39.69 % ***

The other types are within noise (−1.48 % to +1.88 %).

benchmark/buffers/buffer-write.js (30 runs):

type buffer=fast buffer=slow
BigInt64LE +74.00 % *** +76.36 % ***
BigInt64BE +74.64 % *** +73.65 % ***
BigUInt64LE +68.63 % *** +68.76 % ***
BigUInt64BE +68.04 % *** +68.28 % ***

readBig(U)Int64{LE,BE}() and writeBig(U)Int64{LE,BE}() assembled and
split values with BigInt arithmetic, allocating intermediate BigInts on
every call. Copy the bytes through BigInt64Array and BigUint64Array
views over the existing 8-byte scratch buffer instead, as the double
accessors already do.

Range and bounds checks are unchanged, and the value is masked with
`& -1n` before the store so non-BigInt values still throw the same
TypeError instead of being coerced by the typed array.

benchmark/buffers/buffer-read.js now uses the value it reads. The
loop discarded it, which let V8 remove side-effect-free reads
altogether.

Assisted-by: claude:opus-5.5
Signed-off-by: Gürgün Dayıoğlu <hey@gurgun.day>
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/performance

@nodejs-github-bot nodejs-github-bot added buffer Issues and PRs related to the buffer subsystem. needs-ci PRs that need a full CI run. labels Nov 17, 2026
@gurgunday gurgunday added the performance Issues and PRs related to the performance of Node.js. label Nov 17, 2026
@codecov

codecov Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.68%. Comparing base (55da353) to head (6d52376).
⚠️ Report is 78 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #67549      +/-   ##
==========================================
+ Coverage   90.66%   90.68%   +0.01%     
==========================================
  Files         799      800       +1     
  Lines      280245   280963     +718     
  Branches    54121    54287     +166     
==========================================
+ Hits       254097   254800     +703     
+ Misses      16277    16254      -23     
- Partials     9871     9909      +38     
Files with missing lines Coverage Δ
lib/internal/buffer.js 98.92% <100.00%> (-0.04%) ⬇️

... and 82 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.

@mcollina mcollina 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

@gurgunday gurgunday added request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. author ready PRs with CI started, the required approvals, and no outstanding review comments. labels Nov 17, 2026
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Nov 17, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@gurgunday gurgunday added the resume-ci Add this label to resume the latest eligible Jenkins CI run on a PR with an approving review. label Nov 18, 2026
@github-actions github-actions Bot removed the resume-ci Add this label to resume the latest eligible Jenkins CI run on a PR with an approving review. label Nov 18, 2026
@jasnell jasnell added the resume-ci Add this label to resume the latest eligible Jenkins CI run on a PR with an approving review. label Nov 18, 2026
@github-actions github-actions Bot removed the resume-ci Add this label to resume the latest eligible Jenkins CI run on a PR with an approving review. label Nov 18, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@gurgunday gurgunday added the commit-queue PRs queued for automated landing through the Commit Queue. label Nov 18, 2026
@nodejs-github-bot
nodejs-github-bot merged commit 41918c1 into nodejs:main Nov 19, 2026
92 checks passed
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Landed in 41918c1

@nodejs-github-bot nodejs-github-bot removed the commit-queue PRs queued for automated landing through the Commit Queue. label Nov 19, 2026
snovader added a commit to snovader/tafla that referenced this pull request Nov 19, 2026
readInt64() and readUint64() added a value's two 32-bit words as bigints,
which allocated a bigint for each. They now copy the bytes to a scratch
DataView and read the value from it, as readFloat64() does, and as
nodejs/node#67549 changed Buffer's accessors to.
aduh95 pushed a commit that referenced this pull request Nov 20, 2026
readBig(U)Int64{LE,BE}() and writeBig(U)Int64{LE,BE}() assembled and
split values with BigInt arithmetic, allocating intermediate BigInts on
every call. Copy the bytes through BigInt64Array and BigUint64Array
views over the existing 8-byte scratch buffer instead, as the double
accessors already do.

Range and bounds checks are unchanged, and the value is masked with
`& -1n` before the store so non-BigInt values still throw the same
TypeError instead of being coerced by the typed array.

benchmark/buffers/buffer-read.js now uses the value it reads. The
loop discarded it, which let V8 remove side-effect-free reads
altogether.

Assisted-by: claude:opus-5.5
Signed-off-by: Gürgün Dayıoğlu <hey@gurgun.day>
PR-URL: #67549
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author ready PRs with CI started, the required approvals, and no outstanding review comments. buffer Issues and PRs related to the buffer subsystem. needs-ci PRs that need a full CI run. performance Issues and PRs related to the performance of Node.js.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants