stream: optimize webstreams pipeTo further#62079
stream: optimize webstreams pipeTo further#62079nodejs-github-bot merged 5 commits intonodejs:mainfrom
pipeTo further#62079Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #62079 +/- ##
==========================================
- Coverage 89.75% 89.64% -0.11%
==========================================
Files 674 676 +2
Lines 204886 206310 +1424
Branches 39376 39520 +144
==========================================
+ Hits 183894 184951 +1057
- Misses 13280 13480 +200
- Partials 7712 7879 +167
🚀 New features to boost your workflow:
|
|
I finally figured out how to do a proper benchmark comparison. (Am I a real scientist now? 😄) These are the raw results: webstreams.csv. node-benchmark-compare confirms a 6%~7% improvement: |
|
cc @nodejs/web-standards for reviews |
Commit Queue failed- Loading data for nodejs/node/pull/62079 ✔ Done loading data for nodejs/node/pull/62079 ----------------------------------- PR info ------------------------------------ Title stream: optimize webstreams `pipeTo` further (#62079) ⚠ Could not retrieve the email or name of the PR author's from user's GitHub profile! Branch MattiasBuelens:webstreams-optimize-pipeto -> nodejs:main Labels needs-ci, web streams Commits 5 - stream: optimize webstreams pipeTo - fixup! do not use writer public API - fixup! optimize backpressure check - fixup! wait for ready only if there is backpressure - fixup! disturbed is already true at start of pipeTo Committers 1 - Mattias Buelens <mattias@buelens.com> PR-URL: https://github.com/nodejs/node/pull/62079 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> ------------------------------ Generated metadata ------------------------------ PR-URL: https://github.com/nodejs/node/pull/62079 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> -------------------------------------------------------------------------------- ℹ This PR was created on Mon, 02 Mar 2026 21:06:20 GMT ✔ Approvals: 2 ✔ - James M Snell (@jasnell) (TSC): https://github.com/nodejs/node/pull/62079#pullrequestreview-3878880914 ✔ - Matteo Collina (@mcollina) (TSC): https://github.com/nodejs/node/pull/62079#pullrequestreview-3912132009 ✔ Last GitHub CI successful ℹ Last Full PR CI on 2026-03-03T13:30:17Z: https://ci.nodejs.org/job/node-test-pull-request/71543/ - Querying data for job/node-test-pull-request/71543/ ✔ 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 62079 From https://github.com/nodejs/node * branch refs/pull/62079/merge -> FETCH_HEAD ✔ Fetched commits as f38a73962384..7b31401e6d9a -------------------------------------------------------------------------------- Auto-merging lib/internal/webstreams/readablestream.js [main bd9b38ce57] stream: optimize webstreams pipeTo Author: Mattias Buelens <mattias@buelens.com> Date: Sun Mar 1 13:33:20 2026 +0100 1 file changed, 1 insertion(+), 4 deletions(-) Auto-merging lib/internal/webstreams/readablestream.js [main 8f72309155] fixup! do not use writer public API Author: Mattias Buelens <mattias@buelens.com> Date: Sun Mar 1 13:35:28 2026 +0100 1 file changed, 2 insertions(+), 1 deletion(-) Auto-merging lib/internal/webstreams/readablestream.js [main 0124d30806] fixup! optimize backpressure check Author: Mattias Buelens <mattias@buelens.com> Date: Sun Mar 1 13:56:04 2026 +0100 1 file changed, 6 insertions(+), 7 deletions(-) Auto-merging lib/internal/webstreams/readablestream.js [main fc8a6fb91a] fixup! wait for ready only if there is backpressure Author: Mattias Buelens <mattias@buelens.com> Date: Mon Mar 2 20:58:14 2026 +0100 1 file changed, 5 insertions(+), 3 deletions(-) Auto-merging lib/internal/webstreams/readablestream.js [main 78f7f67869] fixup! disturbed is already true at start of pipeTo Author: Mattias Buelens <mattias@buelens.com> Date: Mon Mar 2 21:04:06 2026 +0100 1 file changed, 1 deletion(-) ✔ Patches applied There are 5 commits in the PR. Attempting autorebase. (node:451) [DEP0190] DeprecationWarning: Passing args to a child process with shell option true can lead to security vulnerabilities, as the arguments are not escaped, only concatenated. (Use `node --trace-deprecation ...` to show where the warning was created) Rebasing (2/10) Executing: git node land --amend --yes --------------------------------- New Message ---------------------------------- stream: optimize webstreams pipeTohttps://github.com/nodejs/node/actions/runs/22831749349 |
|
Landed in f82525e |
PR-URL: #62079 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
PR-URL: #62079 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
I've started looking more closely at the
pipeTo()implementation, and found some low-hanging fruit to further optimize it:await writer.readyevery time, that's only needed if there is backpressure. So we check that first.writer.desiredSizeto check if there is backpressure, we can read that directly from the internal state of theWritableStreamDefaultController.readableStreamDefaultControllerCallPullIfNeededalready checksstate === 'readable' && !closeRequestedthroughreadableStreamDefaultControllerCanCloseOrEnqueue, so we don't have to repeat that check.This also fixes a few more edge cases:
writer.desiredSizeinsidepipeTo(), which is part of the publicWritableStreamDefaultWriterAPI, and step 15 of the spec explicitly forbids using the public API since it can be modified by user-land code. We now bypass this entirely usingdest[kState].backpressure.patched-global.any.jssuite.On my machine, this improves the
webstreams/pipe-to.jsbenchmark by 3% to 7%:Baseline @ 199daab
This PR @ 7b31401