Skip to content

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

Open
mcollina wants to merge 2 commits into
nodejs:mainfrom
mcollina:webstream-perf-round9
Open

stream: fold desired-size check into WHATWG backpressure update#64451
mcollina wants to merge 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.

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

codecov Bot 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 13 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 lines Coverage Δ
lib/internal/webstreams/readablestream.js 98.19% <100.00%> (+<0.01%) ⬆️
lib/internal/webstreams/util.js 97.71% <100.00%> (+<0.01%) ⬆️
lib/internal/webstreams/writablestream.js 99.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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-ci PRs that need a full CI run. web streams

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants