perf(ext/web): convert hot stream queues to O(1) Queue, cache _state reads (#34437)
Three internal slots in the Web Streams implementation were backed by plain arrays and dequeued with `ArrayPrototypeShift`, which is O(n) and re-allocates the array's head on every removal: `WritableStream` `_writeRequests`, `ReadableByteStreamController` `_pendingPullIntos`, and `ReadableStreamBYOBReader` `_readIntoRequests`. They are now backed by the same `Queue` class already used for `_readRequests`, so dequeue is O(1). This also removes a polymorphic IC between `_readRequests` (`Queue`: `.size` / `.dequeue()`) and `_readIntoRequests` (`Array`: `.length` / `shift`) in helpers that touch both reader kinds. While here, repeated `stream[_state]` symbol reads in the hottest paths (`readableStreamDefaultReaderRead`, `readableStreamReaderGenericInitialize`, `readableStreamCancel`) are hoisted into locals, and a redundant `controller[_stream][_state]` chained read in `readableByteStreamControllerEnqueue` now reuses the already-cached `stream` local. Follow-up to #32652. A new `tests/bench/streams.js` exercises the touched paths: default reader reads, many concurrent writes, the BYOB pull-into pipeline, and a `TransformStream` pipe-through.
B
Bartek Iwańczuk committed
c9793456f9aa6fba585b1efffa3ccd87896b7209
Parent: 9de435a
Committed by GitHub <noreply@github.com>
on 5/30/2026, 7:13:16 AM