stream: fold desired-size check into WHATWG backpressure update#64451
Conversation
The [[queue]] backing the controllers became a ring buffer, but the read and write request queues (readRequests, readIntoRequests, writeRequests) were left as plain arrays consumed with ArrayPrototypeShift, which is O(n) and, even for the single pending request of the await-each regime, far slower than an indexed head advance. Back them with the same Queue, materialized lazily from the shared empty queue so acquiring a reader or constructing a writer allocates no request storage until a read or write actually parks. pipe-to: +4.7% to +9.4% (all 16 configs, ***) readable-read type=byob: +2.3% (**) parked read loop: +15%, write loop: +11% (local harness) Follow-up to nodejs#64312. Signed-off-by: Matteo Collina <hello@matteocollina.com>
writableStreamUpdateBackpressure ran two release-mode assertions and took a precomputed backpressure value that every caller derived with a separate GetBackpressure/GetDesiredSize call pair. All callers already hold the 'writable', not-close-queued invariant the assertions checked, so derive the backpressure from the desired size inside the function and drop the assertions and the helper. This runs up to twice per write. writer.write() loop: +10%, pipe-to: +4.6% avg over 16 configs (local harness / benchmark, all configs positive). Signed-off-by: Matteo Collina <hello@matteocollina.com>
Codecov Reportβ
All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #64451 +/- ##
==========================================
- Coverage 90.24% 90.24% -0.01%
==========================================
Files 741 741
Lines 241384 241610 +226
Branches 45480 45519 +39
==========================================
+ Hits 217844 218041 +197
- Misses 15097 15110 +13
- Partials 8443 8459 +16
π New features to boost your workflow:
|
This comment was marked as outdated.
This comment was marked as outdated.
|
@trivikr can you review? |
Commit Queue failed- Loading data for nodejs/node/pull/64451 β Done loading data for nodejs/node/pull/64451 ----------------------------------- PR info ------------------------------------ Title stream: fold desired-size check into WHATWG backpressure update (#64451) Author Matteo Collina <matteo.collina@gmail.com> (@mcollina) Branch mcollina:webstream-perf-round9 -> nodejs:main Labels author ready, needs-ci, web streams Commits 2 - stream: use the ring buffer for WHATWG stream request queues - stream: fold desired-size check into WHATWG backpressure update Committers 1 - Matteo Collina <hello@matteocollina.com> PR-URL: https://github.com/nodejs/node/pull/64451 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> ------------------------------ Generated metadata ------------------------------ PR-URL: https://github.com/nodejs/node/pull/64451 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> -------------------------------------------------------------------------------- βΉ This PR was created on Sun, 12 Jul 2026 15:12:39 GMT β Approvals: 2 β - James M Snell (@jasnell) (TSC): https://github.com/nodejs/node/pull/64451#pullrequestreview-4680407396 β - Trivikram Kamat (@trivikr): https://github.com/nodejs/node/pull/64451#pullrequestreview-4710339944 β Last GitHub CI successful βΉ Last Full PR CI on 2026-07-13T20:49:57Z: https://ci.nodejs.org/job/node-test-pull-request/74797/ - Querying data for job/node-test-pull-request/74797/ β Build data downloaded β Last Jenkins CI successful -------------------------------------------------------------------------------- β No git cherry-pick in progress β No git am in progress β No git rebase in progress -------------------------------------------------------------------------------- - Bringing origin/main up to date... From https://github.com/nodejs/node * branch main -> FETCH_HEAD 608112affa..874e96ee4c main -> origin/main β origin/main is now up-to-date main is out of sync with origin/main. Mismatched commits: - d91a9207a0 stream: validate writer options signal - 874e96ee4c stream: validate writer options signal -------------------------------------------------------------------------------- HEAD is now at 874e96ee4c stream: validate writer options signal β Reset to origin/main - Downloading patch for 64451 From https://github.com/nodejs/node * branch refs/pull/64451/merge -> FETCH_HEAD β Fetched commits as 608112affae2..3cb9f689c486 -------------------------------------------------------------------------------- The previous cherry-pick is now empty, possibly due to conflict resolution. If you wish to commit it anyway, use:https://github.com/nodejs/node/actions/runs/29477179597 |
Commit Queue failed- Loading data for nodejs/node/pull/64451 β Done loading data for nodejs/node/pull/64451 ----------------------------------- PR info ------------------------------------ Title stream: fold desired-size check into WHATWG backpressure update (#64451) Author Matteo Collina <matteo.collina@gmail.com> (@mcollina) Branch mcollina:webstream-perf-round9 -> nodejs:main Labels author ready, needs-ci, web streams, commit-queue-squash Commits 2 - stream: use the ring buffer for WHATWG stream request queues - stream: fold desired-size check into WHATWG backpressure update Committers 1 - Matteo Collina <hello@matteocollina.com> PR-URL: https://github.com/nodejs/node/pull/64451 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> ------------------------------ Generated metadata ------------------------------ PR-URL: https://github.com/nodejs/node/pull/64451 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> -------------------------------------------------------------------------------- βΉ This PR was created on Sun, 12 Jul 2026 15:12:39 GMT β Approvals: 2 β - James M Snell (@jasnell) (TSC): https://github.com/nodejs/node/pull/64451#pullrequestreview-4680407396 β - Trivikram Kamat (@trivikr): https://github.com/nodejs/node/pull/64451#pullrequestreview-4710339944 β Last GitHub CI successful βΉ Last Full PR CI on 2026-07-16T06:41:31Z: https://ci.nodejs.org/job/node-test-pull-request/74797/ - Querying data for job/node-test-pull-request/74797/ β Build data downloaded β Last Jenkins CI successful -------------------------------------------------------------------------------- β No git cherry-pick in progress β No git am in progress β No git rebase in progress -------------------------------------------------------------------------------- - Bringing origin/main up to date... From https://github.com/nodejs/node * branch main -> FETCH_HEAD β origin/main is now up-to-date - Downloading patch for 64451 From https://github.com/nodejs/node * branch refs/pull/64451/merge -> FETCH_HEAD β Fetched commits as 608112affae2..3cb9f689c486 -------------------------------------------------------------------------------- The previous cherry-pick is now empty, possibly due to conflict resolution. If you wish to commit it anyway, use:https://github.com/nodejs/node/actions/runs/29483233622 |
|
Landed in cf882a7 |
writableStreamUpdateBackpressureran two release-mode assertions and took a precomputed backpressure value that every caller derived with a separateGetBackpressure/GetDesiredSizecall pair. All callers already hold thewritable, not-close-queued invariant the assertions checked, so the backpressure is now derived from the desired size inside the function, dropping the assertions and the helper. This runs up to twice per write.The first commit is #64431; only the last commit is new here.