Skip to content

stream: fold desired-size check into WHATWG backpressure update - #64451

Merged
aduh95 merged 2 commits into
nodejs:mainfrom
mcollina:webstream-perf-round9
Jul 16, 2026
Merged

stream: fold desired-size check into WHATWG backpressure update#64451
aduh95 merged 2 commits into
nodejs:mainfrom
mcollina:webstream-perf-round9

Conversation

@mcollina

Copy link
Copy Markdown
Member

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 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.

writer.write() loop: +10% (local harness)
pipe-to: +4.6% avg over 16 configs, all positive (benchmark, 20 runs)

The first commit is #64431; only the last commit is new here.

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>
@nodejs-github-botnodejs-github-bot added needs-ci PRs that need a full CI run. web streams labels Jul 12, 2026
@codecov

codecovBot commented Jul 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.24%. Comparing base (8a3b11c) to head (3cb9f68).
⚠️ Report is 45 commits behind head on main.

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 
Files with missing linesCoverage Δ
lib/internal/webstreams/readablestream.js98.19% <100.00%> (+<0.01%)⬆️
lib/internal/webstreams/util.js97.71% <100.00%> (+<0.01%)⬆️
lib/internal/webstreams/writablestream.js99.50% <100.00%> (-0.01%)⬇️

... and 47 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@mcollinamcollina added the request-ci Add this label to start a Jenkins CI on a PR. label Jul 13, 2026
@github-actionsgithub-actionsBot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jul 13, 2026
@nodejs-github-bot

This comment was marked as outdated.

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@trivikrtrivikr added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Jul 14, 2026
@mcollina

Copy link
Copy Markdown
MemberAuthor

@trivikr can you review?

@trivikrtrivikr left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@mcollinamcollina added the commit-queue Add this label to land a pull request using GitHub Actions. label Jul 16, 2026
@nodejs-github-botnodejs-github-bot added commit-queue-failed An error occurred while landing this pull request using GitHub Actions. and removed commit-queue Add this label to land a pull request using GitHub Actions. labels Jul 16, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator
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:
git commit --allow-empty

Otherwise, please use 'git cherry-pick --skip'
On branch main
Your branch is up to date with 'origin/main'.

You are currently cherry-picking commit e65f9befaf.
(all conflicts fixed: run "git cherry-pick --continue")
(use "git cherry-pick --skip" to skip this patch)
(use "git cherry-pick --abort" to cancel the cherry-pick operation)

Untracked files:
(use "git add <file>..." to include in what will be committed)
labels.json
output

nothing added to commit but untracked files present (use "git add" to track)
✘ Failed to apply patches

https://github.com/nodejs/node/actions/runs/29477179597

@mcollinamcollina added commit-queue Add this label to land a pull request using GitHub Actions. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. and removed commit-queue-failed An error occurred while landing this pull request using GitHub Actions. labels Jul 16, 2026
@nodejs-github-botnodejs-github-bot added commit-queue-failed An error occurred while landing this pull request using GitHub Actions. and removed commit-queue Add this label to land a pull request using GitHub Actions. labels Jul 16, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator
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:
git commit --allow-empty

Otherwise, please use 'git cherry-pick --skip'
On branch main
Your branch is up to date with 'origin/main'.

You are currently cherry-picking commit e65f9befaf.
(all conflicts fixed: run "git cherry-pick --continue")
(use "git cherry-pick --skip" to skip this patch)
(use "git cherry-pick --abort" to cancel the cherry-pick operation)

Untracked files:
(use "git add <file>..." to include in what will be committed)
labels.json
output

nothing added to commit but untracked files present (use "git add" to track)
✘ Failed to apply patches

https://github.com/nodejs/node/actions/runs/29483233622

@aduh95
aduh95 merged commit cf882a7 into nodejs:mainJul 16, 2026
100 checks passed
@aduh95

Copy link
Copy Markdown
Contributor

Landed in cf882a7

aduh95 pushed a commit that referenced this pull request Jul 21, 2026
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>
PR-URL: #64451
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
aduh95 pushed a commit that referenced this pull request Jul 21, 2026
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>
PR-URL: #64451
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
RafaelGSS pushed a commit that referenced this pull request Jul 29, 2026
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>
PR-URL: #64451
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author readyPRs that have at least one approval, no pending requests for changes, and a CI started.commit-queue-failedAn error occurred while landing this pull request using GitHub Actions.commit-queue-squashAdd this label to instruct the Commit Queue to squash all the PR commits into the first one.needs-ciPRs that need a full CI run.web streams

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

@mcollina@nodejs-github-bot@aduh95@jasnell@trivikr