GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — buffer: limit UTF-8 fast calls to safe one-byte strings by ronag · Pull Request #67136 · nodejs/node Conversation
|
| 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.
There was an error while loading. Please reload this page.
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]>
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
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 🎉
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:
-1 without inspecting the string.| 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.
There was an error while loading. Please reload this page.
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]>
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
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.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
lgtm
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Codecov Report✅ All modified and coverable lines are covered by tests. 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
🚀 New features to boost your workflow:
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Landed in bf246cf |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
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]>
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]>
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]>
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]>
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]>
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]>
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]>
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]>
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]>
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.