zlib,url: avoid flattening strings in value-returning fast API calls #67536
All Vouch review confidence checks passed
Residual risk 0.19 = Change Risk (0.45) × (1 − Review Confidence (0.57)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.45 · 408 lines diff across 5 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.360
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #67536"
general
weight: 0.35
anonrig
zlib.crc32(),zlib.crc32c()(string input) andURL.canParse()can abort the process with:This is the same crash as #66870, which #67136 fixed for
Buffer.byteLength(). The fast callbacks of these APIs flatten or convert their string argument (Utf8Value/String::ValueView, andToString()incanParse). Flattening a large non-flat string allocates; if that allocation triggers a full GC that invalidates the optimized caller (for example by clearing a weakly embedded map), V8 has to lazily deoptimize the caller once the fast call returns. V8 does not support that for fast calls that return a value and runsBuiltin::kAbortinstead (crbug.com/418936518, seeFastApiCallReducerAssembler::ReduceFastApiCallindeps/v8/src/compiler/js-call-reducer.cc).Changes:
crc32()/crc32c()now goes through a regular binding. The fast bindings only take ArrayBufferViews, which are read without allocating.canParse()fast path now takes a sequential one-byte string (FastOneByteString), which V8 passes without allocating, and returns-1for anything else so JavaScript calls the regular binding, the same approach as #67136.ToString()is no longer called inside a fast callback.test/parallel/test-fast-api-calls-gc-lazy-deopt.jsoptimizes a caller of each API, drops the only object with a weakly embedded map, and calls it with non-flat old-space strings so that a full GC runs while the string is read. It aborts on v27.0.0-alpha.0.1.0 and passes with this change.I reproduced the abort on 25.0.0 to 26.13.1 and on v27.0.0-alpha.0.1.0 (
crc32andcanParse;byteLengthis already fixed there by #67136).One note on
URL.canParse(): the interpreter only ever sees the slow callback's-1, so the first optimized call at a call site deopts once (insufficient feedback for theresult === 1compare) and is then re-optimized.canParse()gets faster for ASCII input, since the fast path no longer converts or copies the string.crc32()/crc32c()are unchanged for buffers and large strings; very short string inputs may be somewhat slower because strings no longer take the fast call. These numbers come frombenchmark/compare.jswith 8 runs on a laptop, so small differences are noise; a benchmark CI run would give firmer numbers.<img width="1228" height="649" alt="image" src="https://github.com/user-attachments/assets/4e5d1678-d95d-4cad-bab5-1b23fe7a550e" />
permission.has()uses the same pattern (Utf8Valuein a value-returning fast callback), but I have not reproduced the crash there, so it is not part of this PR.AI disclosure: I used a coding agent to help with the root-cause analysis and the initial patch. I reviewed the change, reproduced the crash on the versions above, checked that the new test fails without the fix, and ran
make lint,make format-cpp, and the zlib, url andBuffer.byteLengthtests (parallel/test-zlib,parallel/test-whatwg-url,parallel/test-url,parallel/test-buffer-bytelength). I have not run the fullmake -j4 test.Refs: https://github.com/nodejs/node/issues/66870
Refs: https://github.com/nodejs/node/pull/67136