stream: avoid per-chunk promises in webstream adapters · nodejs/node@dc25a61 · GitHub
Skip to content

Commit dc25a61

Browse files
mcollinaaduh95
authored andcommitted
stream: avoid per-chunk promises in webstream adapters
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> PR-URL: #65548 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Paolo Insogna <paolo@cowtech.it> Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 6b84ee6 commit dc25a61

3 files changed

Lines changed: 266 additions & 85 deletions

File tree

‎benchmark/webstreams/adapters.js‎

Lines changed: 106 additions & 0 deletions

0 commit comments

Comments
 (0)