stream: avoid per-chunk promises in webstream adapters - #65548
Open
mcollina wants to merge 1 commit into
Open
Conversation
Collaborator
|
Review requested:
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #65548 +/- ##
==========================================
- Coverage 90.13% 90.00% -0.14%
==========================================
Files 751 757 +6
Lines 253639 257451 +3812
Branches 47790 48799 +1009
==========================================
+ Hits 228618 231715 +3097
- Misses 16264 16831 +567
- Partials 8757 8905 +148
🚀 New features to boost your workflow:
|
aduh95
approved these changes
Sep 2, 2026
Readable.fromWeb() and the read side of Duplex.fromWeb() allocated a promise, a read-result object, and two reaction closures for every chunk through reader.read(); a single reused read request now delivers chunks through readableStreamDefaultReaderRead() instead, forwarding each chunk in a microtask to preserve the delivery order relative to errors and destroy. Writable.fromWeb() and the write side of Duplex.fromWeb() paid two derived promises off writer.ready plus the writer.write() promise and a fresh closure pair per chunk; a single shared write request now dispatches chunks directly and settles the node callback, with failures delivered in a microtask. Signed-off-by: Matteo Collina <hello@matteocollina.com>
mcollina
force-pushed
the
webstream-perf-round15
branch
from
September 2, 2026 11:00
5095bc9 to
9c2217a
Compare
ShogunPanda
approved these changes
Sep 3, 2026
Collaborator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Continuing the WHATWG streams optimization work, this round targets the stream/webstream adapters (
Readable.fromWeb(),Writable.fromWeb(),Duplex.fromWeb()), which had never been profiled.Readable.fromWeb()and the read side ofDuplex.fromWeb()allocated a promise, a read-result object, and two reaction closures for every chunk throughreader.read(). Only one read is ever in flight (_readis not called again beforepush()), so a single reused read request now delivers chunks throughreadableStreamDefaultReaderRead(), forwarding each chunk in a microtask to keep the previous delivery order relative to errors and destroy.Writable.fromWeb()and the write side ofDuplex.fromWeb()paid two derived promises offwriter.readyplus thewriter.write()promise and a fresh closure pair per chunk. A single shared write request (the same contractpipeTouses since #64890) now dispatches chunks directly and settles the node callback. Failures are delivered in a microtask because the callback can destroy the stream while the writable machinery is mid-transition.Also adds
benchmark/webstreams/adapters.js— the suite had no rows for the adapter paths.Results (30 runs):
The two
toWebrows are untouched paths and neutral, included for coverage. Beyond the test suite and WPT, the change was validated with a differential stress harness (error mid-write, writev with cork, erroring controller, destroy during data, pre-closed/pre-errored streams, duplex echo, slow-sink backpressure): the observable event logs are byte-identical to the previous implementation.