stream: reduce allocations on WHATWG streams hot paths#63876
Open
mcollina wants to merge 1 commit into
Open
Conversation
MattiasBuelens
left a comment
Contributor
There was a problem hiding this comment.
Looks pretty sensible to me! 👍
anonrig
approved these changes
Jun 13, 2026
Collaborator
Member
Author
|
Updated benchmarks after the regression fix: |
aduh95
reviewed
Jun 13, 2026
6d140aa to
92194f3
Compare
MattiasBuelens
approved these changes
Jun 14, 2026
gurgunday
approved these changes
Jun 14, 2026
92194f3 to
da5b0ee
Compare
jasnell
approved these changes
Jun 14, 2026
Collaborator
Collaborator
Collaborator
aduh95
reviewed
Jun 15, 2026
1d6ccc9 to
04558a1
Compare
aduh95
approved these changes
Jun 20, 2026
Pure-JavaScript optimizations to lib/internal/webstreams/* that reduce per-chunk and per-construction allocations on hot paths without observable behavior change. Per-chunk: reuse promise-reaction closures per controller, add buffered fast path for async iterator, specialize callback wrappers by arity, and share immutable nil records for writable stream resets. Per-construction: use queueMicrotask for non-object start results, materialize reader/writer .closed and .ready records lazily, and remove dead allocations. Assisted-by: Claude Fable 5 Signed-off-by: Matteo Collina <hello@matteocollina.com>
04558a1 to
67d17be
Compare
Collaborator
|
CI: https://ci.nodejs.org/job/node-test-pull-request/74293/ Benchmark results |
gurgunday
approved these changes
Jun 20, 2026
Collaborator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Pure-JavaScript allocation reductions on the WHATWG streams hot paths partially based on the findings of #63872 : reused promise-reaction closures per controller (pull/write), a buffered fast path in the async iterator,
queueMicrotask()for non-thenable start results, arity-specialized algorithm wrappers, shared nil state records, and removal of several dead per-instance allocations. No observable behavior change: WPT streams/compression/encoding results are identical tomain(same subtests passing, same 8 expected failures by name).Benchmark results (
benchmark/compare.js --runs 10, both binaries built the same day from the same toolchain):The
creation.jsrows at the stockn=50000measure a 20-40ms window and are unreliable; re-run at--set n=500000: