stream: trim per-pipe and per-tee costs in webstreams · nodejs/node@3c9f878 · GitHub
Skip to content

Commit 3c9f878

Browse files
mcollinaaduh95
authored andcommitted
stream: trim per-pipe and per-tee costs in webstreams
An object literal with computed symbol keys is rebuilt through the runtime every time it is evaluated, close to a microsecond each. pipeTo, tee and the byte tee materialized their internal read request as such a literal once per pipe or tee, and the byte tee's BYOB path did so on every read. The requests are now instances of one small class holding the three step functions. A source without pull() ran the pull bookkeeping anyway: two reaction closures and a microtask per read whose only effect was to clear the pulling flag. Push-style sources now skip it. The default tee's pull algorithm was an async function and the byte tee's returned a fresh resolved promise; both now return nothing, which reaches the controller's pull-fulfilled step at the same microtask position without the promise. ReadableStreamBYOBReader.prototype.read() was an async method, so the read request's promise was adopted through a wrapper (an extra promise and two microtask hops per read). It now returns the request's promise directly, as the spec does; argument errors still become rejections. A TransformStream without start() no longer allocates the start promise record: the sides adopt a promise that is already resolved either way. Signed-off-by: Matteo Collina <hello@matteocollina.com> PR-URL: #66154 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Mattias Buelens <mattias@buelens.com>
1 parent d5b65c3 commit 3c9f878

2 files changed

Lines changed: 127 additions & 78 deletions

File tree

‎lib/internal/webstreams/readablestream.js‎

Lines changed: 116 additions & 74 deletions

‎lib/internal/webstreams/transformstream.js‎

Lines changed: 11 additions & 4 deletions

0 commit comments

Comments
 (0)