GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — buffer: limit UTF-8 fast calls to safe one-byte strings by ronag · Pull Request #67136 · nodejs/node

Conversation

@ronag

@ronag ronag commented Oct 30, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Alternative to #67134. This is a
standalone change against main; it does not depend on that PR.

Keep a fast UTF-8 byte-length path for sequential one-byte strings.
The fast binding's slow fallback returns the Smi sentinel -1 without
reading or flattening the string. JavaScript then calls the regular
binding separately. Both the fast callback and its fallback avoid JS-heap
allocation; allocating string handling uses an ordinary API continuation.

Validation on Linux x64, GCC 14.2.0, release builds of v28.0.0-pre:

  • Candidate 44bd1bfa65f. The local regular-callback baseline
    35cf29a820a is main 250037174ee with the removal fix from buffer: avoid fast API calls when computing UTF-8 byte length #67134,
    used only for the benchmark comparison.
  • A negative control using a one-byte signature with an allocating slow
    fallback aborts both the direct and HTTP reproducers in 3/3 runs each.
  • The candidate passes the direct reproducer 10/10 and HTTP 5/5. Traces
    show actual lazy deoptimization after weak objects are cleared, followed
    by normal completion, including end() and maybePrepareFinalChunk().
  • All 531 buffer, HTTP, string-decoder and snapshot tests pass, including
    explicit optimized fast-acceptance and rejection checks.
  • Main thread, four workers, and a user-land startup snapshot pass the
    string-representation corpus before and after optimization.
  • Additional GC stress, ESLint, focused binding type checking, cpplint,
    import, C++ formatting and whitespace checks pass.

Benchmark tradeoff versus the regular-callback baseline, ten alternating
runs per binary on one fixed logical CPU, two million calls per case:

UTF-8 input repeat=1 repeat=16 repeat=256
one-byte ASCII +65.03% +/-12.95 -9.70% +/-12.50 -12.64% +/-6.43
Latin-1 +33.18% +/-10.41 -7.12% +/-6.46 -2.15% +/-5.28
two-byte -8.04% +/-4.37 -7.07% +/-4.67 -1.60% +/-5.64

Values are throughput changes with 95% confidence intervals in percentage
points. The repeated one-byte strings take the fallback. Eligible flat
inputs improve, while rejected inputs pay for the additional call.
Latin-1 and base64 encoding controls were also measured; raw results cover
27 configurations and 540 samples. Four comparisons remain significant
at 5% after the benchmark tool's Holm-Bonferroni adjustment.

./node benchmark/compare.js --old ./node-baseline --new ./node-candidate \
  --runs 10 --filter buffer-bytelength-string \
  --set encoding=utf8 --set encoding=latin1 --set encoding=base64 \
  --set type=one_byte --set type=latin1 --set type=two_bytes \
  --set repeat=1 --set repeat=16 --set repeat=256 --set n=2000000 \
  --set CPUSET=1 --no-progress --analyze --csv benchmark.csv buffers

Refs: #66870

AI assistance: Codex helped prepare the implementation and tests.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@ronag
buffer: limit UTF-8 fast calls to safe one-byte strings
3384396
Replace the allocating UTF-8 fast call with a fast binding for
sequential one-byte strings. Its slow fallback only returns a Smi
sentinel. JavaScript sends rejected strings to a separate regular
binding that can flatten strings and handle lazy deoptimization.

Both native callbacks used by the fast API avoid JS-heap allocation.
Add GC regression and string-representation coverage, including
optimized fast acceptance and rejection checks.

Fixes: nodejs#66870
Refs: nodejs#67134
Assisted-by: Codex
Signed-off-by: Robert Nagy <[email protected]>
@ronag
ronag requested a balanced review from Copilot October 30, 2026 08:16
@nodejs-github-bot nodejs-github-bot added buffer Issues and PRs related to the buffer subsystem. c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. typings Issues and PRs related to internal TypeScript declarations. labels Oct 30, 2026
Copilot started reviewing on behalf of ronag October 30, 2026 08:17
View session
Copilot AI reviewed Oct 30, 2026
View reviewed changes

Copilot AI left a comment

Copy link
Copy Markdown

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.

🔵 Needs a closer look

V8-aware maintainer review and supported-platform GC-stress CI are needed to validate the allocation-free callback/fallback contract and fast-call lazy-deoptimization behavior.

No open issues 🎉

What changed in this PR

This PR addresses the Buffer.byteLength() abort reported in #66870 while preserving a fast UTF-8 byte-length path for sequential one-byte strings. Rejected strings use a separate regular binding call so allocating string handling avoids the unsupported fast-call deoptimization path.

Changes:

  • Restricts the native fast callback to one-byte strings and makes its fallback return -1 without inspecting the string.
  • Adds a JavaScript wrapper and binding type declaration for the separate fast path.
  • Adds coverage for optimized acceptance and rejection, string representations, and garbage-collection-triggered deoptimization.
File Description
typings/​internalBinding/​buffer.d.ts Declares the new fast byte-length binding.
test/​parallel/​test-buffer-bytelength-strings.js Checks byte lengths across string representations before and after optimization.
test/​parallel/​test-buffer-bytelength-safe-fast.js Tests fast-path acceptance, rejection, and public API results.
test/​parallel/​test-buffer-bytelength-gc.js Adds regression coverage for deoptimization during string flattening.
src/​node_buffer.cc Implements the restricted fast callback and non-allocating sentinel fallback.
lib/​buffer.js Routes rejected fast calls to the regular UTF-8 binding.

Review effort: Balanced

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@ronag
ronag marked this pull request as ready for review October 30, 2026 08:20
@ronag
ronag marked this pull request as draft October 30, 2026 08:24
@ronag
buffer: preserve the one-byte counting loop
44bd1bf
Keep the existing loop unrolling, variable names and scalar tail. Limit the fast-path changes to the safe input and fallback contract.

Assisted-by: Codex
Signed-off-by: Robert Nagy <[email protected]>
@ronag
ronag requested a balanced review from Copilot October 30, 2026 08:31
Copilot started reviewing on behalf of ronag October 30, 2026 08:31
View session
Copilot AI reviewed Oct 30, 2026
View reviewed changes

Copilot AI left a comment

Copy link
Copy Markdown

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.

🔵 Needs a closer look

V8-aware maintainer review and GC/deoptimization stress validation are needed to confirm the fast-call continuation and no-GC invariants across supported configurations.

No open issues 🎉

Review effort: Balanced

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@ronag
ronag marked this pull request as ready for review October 30, 2026 08:38
@ronag
ronag requested review from anonrig and mcollina October 30, 2026 08:42
mcollina
mcollina approved these changes Oct 30, 2026
View reviewed changes

@mcollina mcollina left a comment

Copy link
Copy Markdown
Member

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.

lgtm

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@ronag ronag added the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Oct 30, 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 Oct 30, 2026
@nodejs-github-bot

nodejs-github-bot commented Oct 30, 2026

Copy link
Copy Markdown
Collaborator

CI: https://ci.nodejs.org/job/node-test-pull-request/78734/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ronag ronag added the author ready PRs with CI started, the required approvals, and no outstanding review comments. label Oct 30, 2026
@codecov

codecov Bot commented Oct 30, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Codecov Report

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

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #67136      +/-   ##
==========================================
+ Coverage   90.67%   90.69%   +0.01%     
==========================================
  Files         797      797              
  Lines      278806   278803       -3     
  Branches    53621    53619       -2     
==========================================
+ Hits       252813   252861      +48     
+ Misses      16341    16305      -36     
+ Partials     9652     9637      -15     
Files with missing lines Coverage Δ
lib/buffer.js 99.74% <100.00%> (+<0.01%) ⬆️
src/node_buffer.cc 74.86% <100.00%> (+3.19%) ⬆️

... and 23 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.
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

anonrig
anonrig approved these changes Oct 30, 2026
View reviewed changes
@ronag ronag added commit-queue PRs queued for automated landing through the Commit Queue. commit-queue-squash PRs the Commit Queue should land as one squashed commit. labels Oct 30, 2026
addaleax
addaleax approved these changes Oct 30, 2026
View reviewed changes
UlisesGascon
UlisesGascon approved these changes Oct 30, 2026
View reviewed changes
@nodejs-github-bot
nodejs-github-bot merged commit bf246cf into nodejs:main Nov 1, 2026
94 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@nodejs-github-bot

nodejs-github-bot commented Nov 1, 2026

Copy link
Copy Markdown
Collaborator

Landed in bf246cf

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@nodejs-github-bot nodejs-github-bot removed the commit-queue PRs queued for automated landing through the Commit Queue. label Nov 1, 2026
@jakesalvesen jakesalvesen mentioned this pull request Nov 1, 2026
Abort "Lazy deopt after a fast API call with return value is unsupported" in Buffer.byteLength called from maybePrepareFinalChunk / res.end(string) #66870
Closed
This was referenced Nov 11, 2026
ci(colab): component-spec web server aborts in V8 ("Lazy deopt after a fast API call") on Node 26.12.1 tmt-ninja/tmt#5846
Open
fix(colab): keep emulator listeners off released ephemeral ports tmt-ninja/tmt#6253
Merged
aduh95 pushed a commit that referenced this pull request Nov 11, 2026
@ronag @aduh95
buffer: limit UTF-8 fast calls to safe one-byte strings
faf48bf
Replace the allocating UTF-8 fast call with a fast binding for
sequential one-byte strings. Its slow fallback only returns a Smi
sentinel. JavaScript sends rejected strings to a separate regular
binding that can flatten strings and handle lazy deoptimization.

Both native callbacks used by the fast API avoid JS-heap allocation.
Add GC regression and string-representation coverage, including
optimized fast acceptance and rejection checks.

Fixes: #66870
Refs: #67134
Assisted-by: Codex
Signed-off-by: Robert Nagy <[email protected]>
PR-URL: #67136
Refs: #66870
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Ulises Gascón <[email protected]>
@github-actions github-actions Bot mentioned this pull request Nov 11, 2026
2026-11-12, Version 27.0.0-alpha.0.1.0 (Alpha) #67415
Merged
aduh95 pushed a commit that referenced this pull request Nov 12, 2026
@ronag @aduh95
buffer: limit UTF-8 fast calls to safe one-byte strings
ba50ace
Replace the allocating UTF-8 fast call with a fast binding for
sequential one-byte strings. Its slow fallback only returns a Smi
sentinel. JavaScript sends rejected strings to a separate regular
binding that can flatten strings and handle lazy deoptimization.

Both native callbacks used by the fast API avoid JS-heap allocation.
Add GC regression and string-representation coverage, including
optimized fast acceptance and rejection checks.

Fixes: #66870
Refs: #67134
Assisted-by: Codex
Signed-off-by: Robert Nagy <[email protected]>
PR-URL: #67136
Refs: #66870
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Ulises Gascón <[email protected]>
@wkh237 wkh237 mentioned this pull request Nov 16, 2026
Guidance hygiene: weekly pass log tmt-ninja/tmt#1506
Open
dasunNimantha added a commit to dasunNimantha/node that referenced this pull request Nov 17, 2026
@dasunNimantha
zlib: avoid flattening strings in crc32 fast path
c3b5553
zlib.crc32() and zlib.crc32c() read string input through a V8 fast API
callback that returns a value. Reading a non-flat (cons) string flattens
it, which allocates on the JS heap. If that allocation triggers a full
GC that invalidates the optimized caller, V8 has to lazily deoptimize it
after the fast call returns, which it does not support for fast calls
with a return value: the process aborts with "Lazy deopt after a fast
API call with return value is unsupported".

Strings now go through a regular binding. The fast bindings are limited
to ArrayBufferViews, which are read without allocating.

Refs: nodejs#66870
Refs: nodejs#67136
Signed-off-by: dasunNimantha <[email protected]>
dasunNimantha added a commit to dasunNimantha/node that referenced this pull request Nov 17, 2026
@dasunNimantha
url: avoid flattening strings in canParse fast path
84c4ae6
URL.canParse() converted and flattened its arguments inside a V8 fast
API callback that returns a value. Like zlib.crc32(), that can allocate
and trigger a GC that invalidates the optimized caller, which V8 then
cannot lazily deoptimize and aborts instead.

The fast path now takes a sequential one-byte string, which V8 passes
without allocating, and returns -1 for anything it cannot handle that
way so that JavaScript falls back to the regular binding.

Refs: nodejs#66870
Refs: nodejs#67136
Signed-off-by: dasunNimantha <[email protected]>
@dasunNimantha dasunNimantha mentioned this pull request Nov 17, 2026
zlib,url: avoid flattening strings in value-returning fast API calls #67536
Open
dasunNimantha added a commit to dasunNimantha/node that referenced this pull request Nov 17, 2026
@dasunNimantha
zlib: avoid flattening strings in crc32 fast path
3f17c06
zlib.crc32() and zlib.crc32c() read string input through a V8 fast API
callback that returns a value. Reading a non-flat (cons) string flattens
it, which allocates on the JS heap. If that allocation triggers a full
GC that invalidates the optimized caller, V8 has to lazily deoptimize it
after the fast call returns, which it does not support for fast calls
with a return value: the process aborts with "Lazy deopt after a fast
API call with return value is unsupported".

Strings now go through a regular binding. The fast bindings are limited
to ArrayBufferViews, which are read without allocating.

Refs: nodejs#66870
Refs: nodejs#67136
Signed-off-by: dasunNimantha <[email protected]>
dasunNimantha added a commit to dasunNimantha/node that referenced this pull request Nov 17, 2026
@dasunNimantha
url: avoid flattening strings in canParse fast path
3d4b619
URL.canParse() converted and flattened its arguments inside a V8 fast
API callback that returns a value. Like zlib.crc32(), that can allocate
and trigger a GC that invalidates the optimized caller, which V8 then
cannot lazily deoptimize and aborts instead.

The fast path now takes a sequential one-byte string, which V8 passes
without allocating, and returns -1 for anything it cannot handle that
way so that JavaScript falls back to the regular binding.

Refs: nodejs#66870
Refs: nodejs#67136
Signed-off-by: dasunNimantha <[email protected]>
@inkless inkless mentioned this pull request Nov 18, 2026
fix(web): run the dev server with V8's fast API calls off inkless/bazhen#344
Merged
inkless added a commit to inkless/bazhen that referenced this pull request Nov 18, 2026
@inkless @claude
fix(web): run the dev server with V8's fast API calls off
48a673e
On Node 26 the web dev server can abort with "Lazy deopt after a fast API
call with return value is unsupported" in Buffer.byteLength, called from
vite's send while it answers a large module (nodejs/node#66870). Here that
is the react-aria-components pre-bundle: 2.2 MB of code with its 4.8 MB
source map inlined as base64, 8.6 MB per response. An e2e run lost its
web server mid-suite to it.

Node fixed Buffer.byteLength on main (nodejs/node#67136), but no released
Node 26 carries it yet. --no-turbo-fast-api-calls stops TurboFan from
emitting the fast call whose lazy deopt aborts, so the dev server can't
take that path whatever the module size. V8 flags aren't accepted in
NODE_OPTIONS, so the web package's dev script starts vite through node
with the flag, and e2e now runs that script instead of calling vite
directly, so both start the server the same way.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
inkless added a commit to inkless/bazhen that referenced this pull request Nov 18, 2026
@inkless @claude
fix(web): run the dev server with V8's fast API calls off (#344)
901fc01
On Node 26 the web dev server can abort with "Lazy deopt after a fast API
call with return value is unsupported" in Buffer.byteLength, called from
vite's send while it answers a large module (nodejs/node#66870). Here that
is the react-aria-components pre-bundle: 2.2 MB of code with its 4.8 MB
source map inlined as base64, 8.6 MB per response. An e2e run lost its
web server mid-suite to it.

Node fixed Buffer.byteLength on main (nodejs/node#67136), but no released
Node 26 carries it yet. --no-turbo-fast-api-calls stops TurboFan from
emitting the fast call whose lazy deopt aborts, so the dev server can't
take that path whatever the module size. V8 flags aren't accepted in
NODE_OPTIONS, so the web package's dev script starts vite through node
with the flag, and e2e now runs that script instead of calling vite
directly, so both start the server the same way.

Co-authored-by: Claude Opus 5.5 <[email protected]>
@jwh3times jwh3times mentioned this pull request Nov 18, 2026
The e2e dev server can crash on a V8 abort under Node 26, failing every test after it jwh3times/LeaseBook#798
Closed
@Seigiard Seigiard mentioned this pull request Nov 20, 2026
TASK-144: Run checks on Node 26 without the test server crash Seigiard/owlbear-muster-roll#101
Merged
@github-actions github-actions Bot mentioned this pull request Nov 20, 2026
2026-11-30, Version 26.14.0 'Lithium' (LTS) #67664
Open
@wkh237 wkh237 mentioned this pull request Nov 22, 2026
ci(browser-ui): a gallery web server that dies mid-run fails the run with its own exit reason tmt-ninja/tmt#6806
Merged
This was referenced Nov 27, 2026
T11: Panel skeletons 6DEADSHOT9/Implicity#55
Merged
Vite dev server aborts in V8 on Node 26.13.1 during long browser repeats 6DEADSHOT9/Implicity#112
Closed
Avoid the V8 fast-API abort in the test dev server 6DEADSHOT9/Implicity#129
Merged
gabylb pushed a commit to gabylb/node that referenced this pull request Nov 27, 2026
@ronag @gabylb
buffer: limit UTF-8 fast calls to safe one-byte strings
32538b1
Replace the allocating UTF-8 fast call with a fast binding for
sequential one-byte strings. Its slow fallback only returns a Smi
sentinel. JavaScript sends rejected strings to a separate regular
binding that can flatten strings and handle lazy deoptimization.

Both native callbacks used by the fast API avoid JS-heap allocation.
Add GC regression and string-representation coverage, including
optimized fast acceptance and rejection checks.

Fixes: nodejs#66870
Refs: nodejs#67134
Assisted-by: Codex
Signed-off-by: Robert Nagy <[email protected]>
PR-URL: nodejs#67136
Refs: nodejs#66870
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Ulises Gascón <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

Copilot code review Copilot
Copilot review effort
Applies to this pull request for everyone.Learn more about Copilot code review.
Copilot left review comments
@mcollina mcollina mcollina approved these changes
@addaleax addaleax addaleax approved these changes
@anonrig anonrig anonrig approved these changes
@UlisesGascon UlisesGascon UlisesGascon approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

author ready PRs with CI started, the required approvals, and no outstanding review comments. buffer Issues and PRs related to the buffer subsystem. c++ Issues and PRs that require attention from people who are familiar with C++. commit-queue-squash PRs the Commit Queue should land as one squashed commit. needs-ci PRs that need a full CI run. typings Issues and PRs related to internal TypeScript declarations.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

7 participants

@ronag @nodejs-github-bot @mcollina @addaleax @anonrig @UlisesGascon
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.