stream: use the ring buffer for WHATWG stream request queues · nodejs/node@0ddfc6a · GitHub
Skip to content

Commit 0ddfc6a

Browse files
mcollinaaduh95
authored andcommitted
stream: use the ring buffer for WHATWG stream request queues
The [[queue]] backing the controllers became a ring buffer, but the read and write request queues (readRequests, readIntoRequests, writeRequests) were left as plain arrays consumed with ArrayPrototypeShift, which is O(n) and, even for the single pending request of the await-each regime, far slower than an indexed head advance. Back them with the same Queue, materialized lazily from the shared empty queue so acquiring a reader or constructing a writer allocates no request storage until a read or write actually parks. pipe-to: +4.7% to +9.4% (all 16 configs, ***) readable-read type=byob: +2.3% (**) parked read loop: +15%, write loop: +11% (local harness) Follow-up to #64312. Signed-off-by: Matteo Collina <hello@matteocollina.com> PR-URL: #64431 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent 8fe5807 commit 0ddfc6a

3 files changed

Lines changed: 54 additions & 38 deletions

File tree

lib/internal/webstreams/readablestream.js

Lines changed: 39 additions & 30 deletions

lib/internal/webstreams/util.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,7 @@ module.exports = {
404404
ArrayBufferViewGetByteLength,
405405
ArrayBufferViewGetByteOffset,
406406
AsyncIterator,
407+
Queue,
407408
canCopyArrayBuffer,
408409
cloneAsUint8Array,
409410
copyArrayBuffer,

lib/internal/webstreams/writablestream.js

Lines changed: 14 additions & 8 deletions

0 commit comments

Comments
 (0)