Skip to content

stream: cut per-chunk overhead in WHATWG streams - #64252

Merged
nodejs-github-bot merged 1 commit into
nodejs:mainfrom
mcollina:webstream-perf-round3
Jul 4, 2026
Merged

nodejs-github-bot merged 1 commit into
nodejs:mainfrom
mcollina:webstream-perf-round3

Conversation

@mcollina

@mcollina mcollina commented Jul 2, 2026

Copy link
Copy Markdown
Member

Consolidates the spec's per-chunk predicate chains into single passes over the controller/stream state, mirrors "close queued or in flight" as a boolean flag, and materializes the TransformStream [[backpressureChangePromise]] record lazily on first observation.

Benchmark results (benchmark/compare.js --runs 10 vs main, same-day build):

webstreams/pipe-to.js (all 16 hwm configs)                 ***  +16.6% .. +23.1%
webstreams/readable-read-buffered.js (all 4 sizes)         ***  +17.7% .. +23.5%
webstreams/readable-async-iterator.js n=100000             ***  +18.4%
webstreams/readable-read.js type='byob' n=100000           ***   +3.6%
webstreams/creation.js kind='TransformStream' n=50000      ***   +6.7%

No regressions on the remaining rows (n.s.). WPT streams/compression/encoding and all parallel whatwg/webstream tests pass unchanged.

@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. web streams Issues and PRs related to the Web Streams API. labels Jul 2, 2026
@mcollina
mcollina requested a review from aduh95 July 2, 2026 08:27
Consolidate the spec's per-chunk predicate chains (CanCloseOrEnqueue,
IsLocked, HasDefaultReader, GetNumReadRequests, GetDesiredSize and the
writable-side equivalents) into single passes over the controller and
stream state, mirror "close queued or in flight" as a boolean flag
maintained at the few close-request transition sites, and materialize
the TransformStream [[backpressureChangePromise]] record lazily on
first observation so backpressure flips nobody is waiting on allocate
nothing.

Assisted-by: Claude Code
Signed-off-by: Matteo Collina <hello@matteocollina.com>
@mcollina
mcollina force-pushed the webstream-perf-round3 branch from ef778b5 to ddba21e Compare July 2, 2026 08:35
@aduh95

aduh95 commented Jul 2, 2026 •

Copy link
Copy Markdown
Contributor

Benchmark CI: https://ci.nodejs.org/view/Node.js%20benchmark/job/benchmark-node-micro-benchmarks/1879/
Benchmark GHA: https://github.com/nodejs/node/actions/runs/28576859103

Results
                                                                       confidence improvement accuracy (*)   (**)  (***)
webstreams/creation.js kind='ReadableStream.tee' n=50000                              -0.07 %       ±0.51% ±0.68% ±0.89%
webstreams/creation.js kind='ReadableStream' n=50000                            *      5.00 %       ±4.75% ±6.33% ±8.23%
webstreams/creation.js kind='ReadableStreamBYOBReader' n=50000                         0.10 %       ±1.39% ±1.85% ±2.40%
webstreams/creation.js kind='ReadableStreamDefaultReader' n=50000                     -0.24 %       ±1.53% ±2.05% ±2.68%
webstreams/creation.js kind='TransformStream' n=50000                         ***     10.64 %       ±1.32% ±1.77% ±2.32%
webstreams/creation.js kind='WritableStream' n=50000                                   1.10 %       ±1.66% ±2.21% ±2.88%
webstreams/js_transfer.js n=10000 payload='ReadableStream'                             0.61 %       ±0.68% ±0.91% ±1.19%
webstreams/js_transfer.js n=10000 payload='TransformStream'                            0.28 %       ±0.42% ±0.56% ±0.74%
webstreams/js_transfer.js n=10000 payload='WritableStream'                             0.36 %       ±0.46% ±0.61% ±0.79%
webstreams/pipe-to.js highWaterMarkW=1024 highWaterMarkR=1024 n=500000        ***     22.40 %       ±1.26% ±1.69% ±2.20%
webstreams/pipe-to.js highWaterMarkW=1024 highWaterMarkR=2048 n=500000        ***     21.74 %       ±1.26% ±1.68% ±2.20%
webstreams/pipe-to.js highWaterMarkW=1024 highWaterMarkR=4096 n=500000        ***     21.97 %       ±1.41% ±1.88% ±2.45%
webstreams/pipe-to.js highWaterMarkW=1024 highWaterMarkR=512 n=500000         ***     21.75 %       ±1.45% ±1.93% ±2.52%
webstreams/pipe-to.js highWaterMarkW=2048 highWaterMarkR=1024 n=500000        ***     20.77 %       ±0.96% ±1.28% ±1.67%
webstreams/pipe-to.js highWaterMarkW=2048 highWaterMarkR=2048 n=500000        ***     21.73 %       ±1.19% ±1.58% ±2.05%
webstreams/pipe-to.js highWaterMarkW=2048 highWaterMarkR=4096 n=500000        ***     20.86 %       ±1.14% ±1.52% ±1.99%
webstreams/pipe-to.js highWaterMarkW=2048 highWaterMarkR=512 n=500000         ***     22.52 %       ±1.47% ±1.95% ±2.55%
webstreams/pipe-to.js highWaterMarkW=4096 highWaterMarkR=1024 n=500000        ***     21.78 %       ±1.48% ±1.96% ±2.56%
webstreams/pipe-to.js highWaterMarkW=4096 highWaterMarkR=2048 n=500000        ***     21.54 %       ±1.50% ±2.00% ±2.60%
webstreams/pipe-to.js highWaterMarkW=4096 highWaterMarkR=4096 n=500000        ***     21.30 %       ±1.42% ±1.89% ±2.47%
webstreams/pipe-to.js highWaterMarkW=4096 highWaterMarkR=512 n=500000         ***     22.06 %       ±1.34% ±1.79% ±2.33%
webstreams/pipe-to.js highWaterMarkW=512 highWaterMarkR=1024 n=500000         ***     20.39 %       ±1.03% ±1.37% ±1.78%
webstreams/pipe-to.js highWaterMarkW=512 highWaterMarkR=2048 n=500000         ***     22.06 %       ±1.46% ±1.95% ±2.54%
webstreams/pipe-to.js highWaterMarkW=512 highWaterMarkR=4096 n=500000         ***     21.28 %       ±1.56% ±2.07% ±2.70%
webstreams/pipe-to.js highWaterMarkW=512 highWaterMarkR=512 n=500000          ***     23.02 %       ±1.38% ±1.84% ±2.40%
webstreams/readable-async-iterator.js n=100000                                ***     20.85 %       ±3.71% ±4.99% ±6.58%
webstreams/readable-read-buffered.js bufferSize=1 n=100000                    ***     19.68 %       ±2.72% ±3.62% ±4.71%
webstreams/readable-read-buffered.js bufferSize=10 n=100000                   ***     21.95 %       ±4.79% ±6.39% ±8.35%
webstreams/readable-read-buffered.js bufferSize=100 n=100000                  ***     15.02 %       ±4.16% ±5.56% ±7.27%
webstreams/readable-read-buffered.js bufferSize=1000 n=100000                 ***     20.77 %       ±3.95% ±5.29% ±6.94%
webstreams/readable-read.js type='byob' n=100000                              ***      2.41 %       ±1.17% ±1.56% ±2.03%
webstreams/readable-read.js type='normal' n=100000                            ***     16.87 %       ±2.32% ±3.09% ±4.02%

Be aware that when doing many comparisons the risk of a false-positive
result increases. In this case, there are 32 comparisons, you can thus
expect the following amount of false-positive results:
  1.60 false positives, when considering a   5% risk acceptance (*, **, ***),
  0.32 false positives, when considering a   1% risk acceptance (**, ***),
  0.03 false positives, when considering a 0.1% risk acceptance (***)

@aduh95 aduh95 added author ready PRs with CI started, the required approvals, and no outstanding review comments. request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. labels Jul 2, 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 Jul 2, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@nodejs-github-bot

This comment was marked as duplicate.

@aduh95 aduh95 added the commit-queue PRs queued for automated landing through the Commit Queue. label Jul 2, 2026
@nodejs-github-bot nodejs-github-bot removed the commit-queue PRs queued for automated landing through the Commit Queue. label Jul 4, 2026
@nodejs-github-bot
nodejs-github-bot merged commit cc05d1c into nodejs:main Jul 4, 2026
93 of 95 checks passed
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Landed in cc05d1c

aduh95 pushed a commit that referenced this pull request Jul 6, 2026
Consolidate the spec's per-chunk predicate chains (CanCloseOrEnqueue,
IsLocked, HasDefaultReader, GetNumReadRequests, GetDesiredSize and the
writable-side equivalents) into single passes over the controller and
stream state, mirror "close queued or in flight" as a boolean flag
maintained at the few close-request transition sites, and materialize
the TransformStream [[backpressureChangePromise]] record lazily on
first observation so backpressure flips nobody is waiting on allocate
nothing.

Assisted-by: Claude Code
Signed-off-by: Matteo Collina <hello@matteocollina.com>
PR-URL: #64252
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
tmeijn pushed a commit to tmeijn/dotfiles that referenced this pull request Jul 9, 2026
This MR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [node](https://nodejs.org) ([source](https://github.com/nodejs/node)) | minor | `26.3.1` → `26.5.0` |

MR created with the help of [el-capitano/tools/renovate-bot](https://gitlab.com/el-capitano/tools/renovate-bot).

**Proposed changes to behavior should be submitted there as MRs.**

---

### Release Notes

<details>
<summary>nodejs/node (node)</summary>

### [`v26.5.0`](https://github.com/nodejs/node/releases/tag/v26.5.0): 2026-07-08, Version 26.5.0 (Current), @&#8203;richardlau

[Compare Source](nodejs/node@v26.3.1...v26.5.0)

##### Notable Changes

##### New release key

Welcome to our newest releaser, [Stewart X Addison](https://github.com/sxa). Future Node.js releases may be signed with his [release key](https://github.com/nodejs/node/blob/main/README.md#release-keys), `655F3B5C1FB3FA8D1A0CA6BDE4A7D232B936D2FD`.

##### Other notable changes

- \[[`55f48446c7`](nodejs/node@55f48446c7)] - **(SEMVER-MINOR)** **buffer**: implement blob.textStream() (Matthew Aitken) [#&#8203;64036](nodejs/node#64036)
- \[[`b373202efc`](nodejs/node@b373202efc)] - **(SEMVER-MINOR)** **esm**: add `--experimental-import-text` flag (Efe) [#&#8203;62300](nodejs/node#62300)
- \[[`39e0c14455`](nodejs/node@39e0c14455)] - **(SEMVER-MINOR)** **perf\_hooks**: sample delay per event loop iteration (Pablo Erhard) [#&#8203;62935](nodejs/node#62935)
- \[[`999a83c937`](nodejs/node@999a83c937)] - **(SEMVER-MINOR)** **stream**: expose ReadableStreamTee (Matteo Collina) [#&#8203;64195](nodejs/node#64195)
- \[[`4e0236dc3d`](nodejs/node@4e0236dc3d)] - **(SEMVER-MINOR)** **tls**: report negotiated TLS groups (Filip Skokan) [#&#8203;64119](nodejs/node#64119)

##### Commits

- \[[`87648c0a6c`](nodejs/node@87648c0a6c)] - **benchmark**: trim down the argon2 sets (Filip Skokan) [#&#8203;64218](nodejs/node#64218)
- \[[`a483bfd3f0`](nodejs/node@a483bfd3f0)] - **buffer**: remove unreachable overflow check in atob (haramjeong) [#&#8203;60161](nodejs/node#60161)
- \[[`6d14279688`](nodejs/node@6d14279688)] - **buffer**: add fast api for isUtf8 and isAscii (Gürgün Dayıoğlu) [#&#8203;64169](nodejs/node#64169)
- \[[`55f48446c7`](nodejs/node@55f48446c7)] - **(SEMVER-MINOR)** **buffer**: implement blob.textStream() (Matthew Aitken) [#&#8203;64036](nodejs/node#64036)
- \[[`a67d9a7a44`](nodejs/node@a67d9a7a44)] - **build**: allow linting node.1 (Aviv Keller) [#&#8203;64157](nodejs/node#64157)
- \[[`06c1fbc25b`](nodejs/node@06c1fbc25b)] - **build**: enable Maglev for riscv64 (Jamie Magee) [#&#8203;62605](nodejs/node#62605)
- \[[`518309c363`](nodejs/node@518309c363)] - **build**: suppress clang errors building libffi on Windows (René) [#&#8203;64222](nodejs/node#64222)
- \[[`6a80ab485c`](nodejs/node@6a80ab485c)] - **build**: add manually-dispatched stress-test workflow (Joyee Cheung) [#&#8203;64118](nodejs/node#64118)
- \[[`f4e7bf1f1c`](nodejs/node@f4e7bf1f1c)] - **build**: pin envinfo versions in github actions (Joyee Cheung) [#&#8203;64117](nodejs/node#64117)
- \[[`66f6ac0d86`](nodejs/node@66f6ac0d86)] - **build**: support setting an emulator from configure script (Ivan Trubach) [#&#8203;53899](nodejs/node#53899)
- \[[`7f26c54aa6`](nodejs/node@7f26c54aa6)] - **child\_process**: fix permission model propagation via NODE\_OPTIONS (Matteo Collina) [#&#8203;63972](nodejs/node#63972)
- \[[`32bb554f5b`](nodejs/node@32bb554f5b)] - **crypto**: fix large DH generator validation (Tobias Nießen) [#&#8203;64092](nodejs/node#64092)
- \[[`0908d76ef6`](nodejs/node@0908d76ef6)] - **crypto**: reject small-order EdDSA points during verify (Filip Skokan) [#&#8203;64026](nodejs/node#64026)
- \[[`7f7e5863c2`](nodejs/node@7f7e5863c2)] - **deps**: update undici to 8.7.0 (Node.js GitHub Bot) [#&#8203;64282](nodejs/node#64282)
- \[[`af91029801`](nodejs/node@af91029801)] - **deps**: update nghttp3 to 1.17.0 (Node.js GitHub Bot) [#&#8203;64182](nodejs/node#64182)
- \[[`2e500ba7b0`](nodejs/node@2e500ba7b0)] - **deps**: update googletest to [`8b53336`](nodejs/node@8b53336) (Node.js GitHub Bot) [#&#8203;64181](nodejs/node#64181)
- \[[`74e3aa24ba`](nodejs/node@74e3aa24ba)] - **deps**: update sqlite to 3.53.3 (Node.js GitHub Bot) [#&#8203;64180](nodejs/node#64180)
- \[[`c7e57f55a7`](nodejs/node@c7e57f55a7)] - **deps**: c-ares: cherry-pick [`8ba37af`](nodejs/node@8ba37af8e3fb) (René) [#&#8203;64110](nodejs/node#64110)
- \[[`879fdc4daf`](nodejs/node@879fdc4daf)] - **deps**: V8: backport [`da20a19`](nodejs/node@da20a197a7f9) (Kevin Gibbons) [#&#8203;64101](nodejs/node#64101)
- \[[`a640543a7c`](nodejs/node@a640543a7c)] - **deps**: V8: cherry-pick [`0cc9eb2`](nodejs/node@0cc9eb22c0b0) (Kevin Gibbons) [#&#8203;64101](nodejs/node#64101)
- \[[`feefd179e5`](nodejs/node@feefd179e5)] - **deps**: V8: cherry-pick [`1a391f9`](nodejs/node@1a391f98cc7a) (Kevin Gibbons) [#&#8203;64101](nodejs/node#64101)
- \[[`8ef643d4b0`](nodejs/node@8ef643d4b0)] - **deps**: update googletest to [`0b1e895`](nodejs/node@0b1e895) (Node.js GitHub Bot) [#&#8203;64039](nodejs/node#64039)
- \[[`9e50bb0655`](nodejs/node@9e50bb0655)] - **dgram**: skip dns.lookup() for literal IP addresses (Ruben Bridgewater) [#&#8203;64133](nodejs/node#64133)
- \[[`dc052c095c`](nodejs/node@dc052c095c)] - **diagnostics\_channel**: return original thenable (Stephen Belanger) [#&#8203;62407](nodejs/node#62407)
- \[[`a22a840293`](nodejs/node@a22a840293)] - **doc**: clarify QUIC stream state wording (EduardF1) [#&#8203;63660](nodejs/node#63660)
- \[[`8d4bec2d71`](nodejs/node@8d4bec2d71)] - **doc**: update Http2SecureServer.on("timeout") default value (YuSheng Chen) [#&#8203;64187](nodejs/node#64187)
- \[[`da88f70afa`](nodejs/node@da88f70afa)] - **doc**: add note on visibility of CI failures to new contributor guide (Stewart X Addison) [#&#8203;64256](nodejs/node#64256)
- \[[`20ce359ccb`](nodejs/node@20ce359ccb)] - **doc**: clarify HTTP/1.1 response ordering (Matteo Collina) [#&#8203;64213](nodejs/node#64213)
- \[[`05eae2835c`](nodejs/node@05eae2835c)] - **doc**: recommend node-stress-single-test for flaky tests (Trivikram Kamat) [#&#8203;64223](nodejs/node#64223)
- \[[`3966eb67e7`](nodejs/node@3966eb67e7)] - **doc**: fix typo in examples (Vas Sudanagunta) [#&#8203;64184](nodejs/node#64184)
- \[[`12a2b9daa3`](nodejs/node@12a2b9daa3)] - **doc**: fix typo in node-config-schema.json (Hamid Reza Ghavami) [#&#8203;64188](nodejs/node#64188)
- \[[`0854482671`](nodejs/node@0854482671)] - **doc**: clarify defense-in-depth issues (Matteo Collina) [#&#8203;64215](nodejs/node#64215)
- \[[`ef4915fc3a`](nodejs/node@ef4915fc3a)] - **doc**: fix Fast FFI argument count in ffi.md (Daijiro Wachi) [#&#8203;63960](nodejs/node#63960)
- \[[`bb2eed863c`](nodejs/node@bb2eed863c)] - **doc**: add sxa GPG key ([`ed25519`](nodejs/node@ed25519)) (Stewart X Addison) [#&#8203;64193](nodejs/node#64193)
- \[[`b7bf6e3a06`](nodejs/node@b7bf6e3a06)] - **doc**: add guide and answers to FAQs for first-time contributors (Joyee Cheung) [#&#8203;63685](nodejs/node#63685)
- \[[`ff537ba858`](nodejs/node@ff537ba858)] - **doc**: update `Http2Server.close` & `Http2SecureServer.close` (YuSheng Chen) [#&#8203;63298](nodejs/node#63298)
- \[[`f3db304588`](nodejs/node@f3db304588)] - **doc**: update list of people in `SECURITY.md` (Richard Lau) [#&#8203;64152](nodejs/node#64152)
- \[[`2a126647b0`](nodejs/node@2a126647b0)] - **doc**: clarify vfs is not a sandbox (Matteo Collina) [#&#8203;64143](nodejs/node#64143)
- \[[`85fc79dd9b`](nodejs/node@85fc79dd9b)] - **doc**: fix broken links and duplicate stability label (Antoine du Hamel) [#&#8203;64130](nodejs/node#64130)
- \[[`189e830eb3`](nodejs/node@189e830eb3)] - **doc**: add missing option to man page (Richard Lau) [#&#8203;64156](nodejs/node#64156)
- \[[`7a16ccccd0`](nodejs/node@7a16ccccd0)] - **doc**: announce upcoming end of tier 2 support for macOS x64 (Antoine du Hamel) [#&#8203;63931](nodejs/node#63931)
- \[[`d5f826045f`](nodejs/node@d5f826045f)] - **doc**: update toolchain for official AIX releases (Richard Lau) [#&#8203;64068](nodejs/node#64068)
- \[[`60abc4400f`](nodejs/node@60abc4400f)] - **doc**: fix callback example import in fs docs (Kamal Rawal) [#&#8203;63912](nodejs/node#63912)
- \[[`e470c74a6c`](nodejs/node@e470c74a6c)] - **doc**: fix keepAliveTimeout default in http.createServer options (Jahanzaib iqbal) [#&#8203;63974](nodejs/node#63974)
- \[[`851b460583`](nodejs/node@851b460583)] - **esm**: improve ERR\_REQUIRE\_ASYNC\_MODULE (Joyee Cheung) [#&#8203;64260](nodejs/node#64260)
- \[[`0cd443df39`](nodejs/node@0cd443df39)] - **esm**: print required top-level await locations without evaluating (Joyee Cheung) [#&#8203;64154](nodejs/node#64154)
- \[[`b373202efc`](nodejs/node@b373202efc)] - **(SEMVER-MINOR)** **esm**: add `--experimental-import-text` flag (Efe) [#&#8203;62300](nodejs/node#62300)
- \[[`eacfbd0ca5`](nodejs/node@eacfbd0ca5)] - **http**: add CONNECT method handling for default Host header with proxy (Archkon) [#&#8203;64114](