stream: trim per-stream costs in webstreams · nodejs/node@a16320e · GitHub
Skip to content

Commit a16320e

Browse files
mcollinaaduh95
authored andcommitted
stream: trim per-stream costs in webstreams
Short-lived streams (create, a few chunks, close) pay a fixed cost per stream that dominates once the per-chunk path is lean. Streams created internally (transform stream sides, tee branches, ReadableStream.from, transferred streams) were built by wrapper constructors that swapped the prototype of every instance and then assigned an own, enumerable `constructor` property to look like a public stream. Each internal stream therefore had its own hidden class and `Object.keys(stream)` reported `['constructor']`. The public constructors now accept the internal construction sentinel and leave controller setup to the caller, so every ReadableStream and WritableStream shares one hidden class and no per-instance prototype swap or own property is needed. The queue ring buffer grew after a push filled it, so the initial 8-slot ring held only three (value, size) pairs and a four-chunk stream reallocated every time. Growing before the push lets the ring hold four pairs. pipeTo observed the source's closed promise with two reactions and, on teardown, let the reader and writer release paths probe and reject promise records that only the pipe could have observed. One reaction pair now watches the source, and finalize drops the records before release. Signed-off-by: Matteo Collina <hello@matteocollina.com> PR-URL: #66052 Reviewed-By: Paolo Insogna <paolo@cowtech.it> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
1 parent 8ec2a94 commit a16320e

3 files changed

Lines changed: 103 additions & 150 deletions

File tree

‎lib/internal/webstreams/readablestream.js‎

Lines changed: 69 additions & 94 deletions

‎lib/internal/webstreams/util.js‎

Lines changed: 9 additions & 7 deletions

0 commit comments

Comments
 (0)