Skip to content

stream: use the ring buffer for WHATWG stream request queues#64431

Open
mcollina wants to merge 1 commit into
nodejs:mainfrom
mcollina:webstream-perf-round8
Open

stream: use the ring buffer for WHATWG stream request queues#64431
mcollina wants to merge 1 commit into
nodejs:mainfrom
mcollina:webstream-perf-round8

Conversation

@mcollina

@mcollina mcollina commented Jul 11, 2026

Copy link
Copy Markdown
Member

The [[queue]] backing the controllers is now a ring buffer, but the read/write request queues (readRequests, readIntoRequests, writeRequests) were left as plain arrays consumed with ArrayPrototypeShift. 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/write parks.

pipe-to: +4.7% to +9.4% (all 16 configs, ***)
readable-read type=byob: +2.3% (**)
parked reader.read() loop: +15%, writer.write() loop: +11% (local harness)

Follow-up to #64312.

@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. web streams labels Jul 11, 2026
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 reader.read() loop: +15%, writer.write() loop: +11% (local harness)

Follow-up to nodejs#64312.

Signed-off-by: Matteo Collina <hello@matteocollina.com>
@mcollina mcollina force-pushed the webstream-perf-round8 branch from e8dd939 to e203888 Compare July 11, 2026 20:48
@mertcanaltin

mertcanaltin commented Jul 11, 2026

Copy link
Copy Markdown
Member

Need a signature for first commit message.

@codecov

codecov Bot commented Jul 11, 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 (e203888).

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #64431      +/-   ##
==========================================
- Coverage   90.24%   90.24%   -0.01%     
==========================================
  Files         741      741              
  Lines      241384   241400      +16     
  Branches    45480    45484       +4     
==========================================
+ Hits       217844   217854      +10     
+ Misses      15097    15093       -4     
- Partials     8443     8453      +10     
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 35 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