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
@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.23%. Comparing base (8a3b11c) to head (e65f9be).
⚠️ Report is 14 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #64431      +/-   ##
==========================================
- Coverage   90.24%   90.23%   -0.01%     
==========================================
  Files         741      741              
  Lines      241384   241391       +7     
  Branches    45480    45487       +7     
==========================================
- Hits       217844   217827      -17     
- Misses      15097    15129      +32     
+ Partials     8443     8435       -8     
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 40 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.

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>
@mcollina mcollina force-pushed the webstream-perf-round8 branch from e203888 to e65f9be Compare July 12, 2026 10:48
@mcollina mcollina added the request-ci Add this label to start a Jenkins CI on a PR. label Jul 12, 2026
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jul 12, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

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.

4 participants