Skip to content

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

Merged
nodejs-github-bot merged 1 commit into
nodejs:mainfrom
mcollina:webstream-perf-round8
Jul 13, 2026
Merged

stream: use the ring buffer for WHATWG stream request queues#64431
nodejs-github-bot merged 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 17 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

@mcollina mcollina requested a review from aduh95 July 13, 2026 07:47
@github-actions

github-actions Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Benchmark GHA (webstreams): https://github.com/nodejs/node/actions/runs/29233460863

Results

[!WARNING]
Do not take GHA benchmark results as face value, always confirm them
using a dedicated machine, e.g. Jenkins CI.

Benchmark results:

                                                                       confidence improvement accuracy (*)    (**)   (***)
webstreams/creation.js kind='ReadableStream.tee' n=50000                               0.64 %       ±6.98%  ±9.19% ±11.80%
webstreams/creation.js kind='ReadableStream' n=50000                                   0.75 %       ±7.98% ±10.51% ±13.49%
webstreams/creation.js kind='ReadableStreamBYOBReader' n=50000                         3.30 %       ±6.13%  ±8.08% ±10.36%
webstreams/creation.js kind='ReadableStreamDefaultReader' n=50000                      1.63 %       ±7.61% ±10.03% ±12.86%
webstreams/creation.js kind='TransformStream' n=50000                                 -0.51 %       ±7.00%  ±9.23% ±11.84%
webstreams/creation.js kind='WritableStream' n=50000                                  -0.63 %       ±7.84% ±10.33% ±13.26%
webstreams/js_transfer.js n=10000 payload='ReadableStream'                            -0.43 %       ±9.64% ±12.71% ±16.30%
webstreams/js_transfer.js n=10000 payload='TransformStream'                            0.77 %       ±9.28% ±12.23% ±15.70%
webstreams/js_transfer.js n=10000 payload='WritableStream'                             0.83 %       ±9.45% ±12.46% ±15.98%
webstreams/pipe-to.js highWaterMarkW=1024 highWaterMarkR=1024 n=500000          *      7.38 %       ±7.34%  ±9.68% ±12.42%
webstreams/pipe-to.js highWaterMarkW=1024 highWaterMarkR=2048 n=500000          *      8.21 %       ±7.21%  ±9.51% ±12.20%
webstreams/pipe-to.js highWaterMarkW=1024 highWaterMarkR=4096 n=500000          *      7.71 %       ±7.29%  ±9.61% ±12.33%
webstreams/pipe-to.js highWaterMarkW=1024 highWaterMarkR=512 n=500000                  7.03 %       ±7.25%  ±9.56% ±12.27%
webstreams/pipe-to.js highWaterMarkW=2048 highWaterMarkR=1024 n=500000          *      7.39 %       ±7.26%  ±9.57% ±12.28%
webstreams/pipe-to.js highWaterMarkW=2048 highWaterMarkR=2048 n=500000          *      8.57 %       ±7.26%  ±9.57% ±12.28%
webstreams/pipe-to.js highWaterMarkW=2048 highWaterMarkR=4096 n=500000          *      7.49 %       ±7.15%  ±9.43% ±12.10%
webstreams/pipe-to.js highWaterMarkW=2048 highWaterMarkR=512 n=500000           *      7.74 %       ±7.29%  ±9.61% ±12.33%
webstreams/pipe-to.js highWaterMarkW=4096 highWaterMarkR=1024 n=500000          *      7.58 %       ±7.30%  ±9.62% ±12.35%
webstreams/pipe-to.js highWaterMarkW=4096 highWaterMarkR=2048 n=500000          *      9.04 %       ±7.43%  ±9.80% ±12.57%
webstreams/pipe-to.js highWaterMarkW=4096 highWaterMarkR=4096 n=500000          *      9.27 %       ±7.45%  ±9.82% ±12.61%
webstreams/pipe-to.js highWaterMarkW=4096 highWaterMarkR=512 n=500000           *      8.51 %       ±7.42%  ±9.78% ±12.55%
webstreams/pipe-to.js highWaterMarkW=512 highWaterMarkR=1024 n=500000           *      7.52 %       ±7.21%  ±9.51% ±12.20%
webstreams/pipe-to.js highWaterMarkW=512 highWaterMarkR=2048 n=500000           *      8.04 %       ±7.35%  ±9.68% ±12.42%
webstreams/pipe-to.js highWaterMarkW=512 highWaterMarkR=4096 n=500000           *      8.19 %       ±7.32%  ±9.64% ±12.38%
webstreams/pipe-to.js highWaterMarkW=512 highWaterMarkR=512 n=500000                   6.34 %       ±7.18%  ±9.46% ±12.14%
webstreams/readable-async-iterator.js type='bytes' n=100000                            4.92 %       ±9.89% ±13.04% ±16.73%
webstreams/readable-async-iterator.js type='normal' n=100000                           0.64 %       ±7.19%  ±9.47% ±12.15%
webstreams/readable-read-buffered.js bufferSize=1 n=100000                            -0.84 %       ±6.44%  ±8.48% ±10.89%
webstreams/readable-read-buffered.js bufferSize=10 n=100000                           -0.49 %       ±5.97%  ±7.87% ±10.10%
webstreams/readable-read-buffered.js bufferSize=100 n=100000                          -1.56 %       ±6.02%  ±7.94% ±10.18%
webstreams/readable-read-buffered.js bufferSize=1000 n=100000                         -0.08 %       ±6.24%  ±8.23% ±10.56%
webstreams/readable-read.js type='byob' n=100000                                       0.48 %       ±7.52%  ±9.91% ±12.72%
webstreams/readable-read.js type='normal' n=100000                             **      7.82 %       ±5.83%  ±7.69%  ±9.87%

Be aware that when doing many comparisons the risk of a false-positive
result increases. In this case, there are 33 comparisons, you can thus
expect the following amount of false-positive results:
  1.65 false positives, when considering a   5% risk acceptance (*, **, ***),
  0.33 false positives, when considering a   1% risk acceptance (**, ***),
  0.03 false positives, when considering a 0.1% risk acceptance (***)

[!WARNING]
Do not take GHA benchmark results as face value, always confirm them
using a dedicated machine, e.g. Jenkins CI.

@aduh95 aduh95 added author ready PRs that have at least one approval, no pending requests for changes, and a CI started. commit-queue Add this label to land a pull request using GitHub Actions. labels Jul 13, 2026
@nodejs-github-bot nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Jul 13, 2026
@nodejs-github-bot nodejs-github-bot merged commit ace91de into nodejs:main Jul 13, 2026
75 checks passed
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Landed in ace91de

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

Labels

author ready PRs that have at least one approval, no pending requests for changes, and a CI started. needs-ci PRs that need a full CI run. web streams

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants