node/benchmark/webstreams
Matteo Collina 199daab0b0
stream: add fast paths for webstreams read and pipeTo
Add internal fast paths to improve webstreams performance without
changing the public API or breaking spec compliance.

1. ReadableStreamDefaultReader.read() fast path:
   When data is already buffered in the controller's queue, return
   PromiseResolve() directly without creating a DefaultReadRequest
   object. This is spec-compliant because read() returns a Promise,
   and resolved promises still run callbacks in the microtask queue.

2. pipeTo() batch read fast path:
   When data is buffered, batch reads directly from the controller
   queue up to highWaterMark without creating
   PipeToReadableStreamReadRequest objects per chunk. Respects
   backpressure by checking desiredSize after each write.

Benchmark results:
  - pipeTo:          ~11% faster (***)
  - buffered read(): ~17-20% faster (***)

Co-Authored-By: Malte Ubl <malte@vercel.com>
PR-URL: https://github.com/nodejs/node/pull/61807
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
Reviewed-By: Ethan Arrowood <ethan@arrowood.dev>
2026-02-19 21:53:46 +00:00
..
creation.js stream: improve tee perf by reduce ReflectConstruct usages 2023-09-11 07:45:11 +00:00
js_transfer.js stream: reduce overhead of transfer 2023-10-12 14:37:41 +00:00
pipe-to.js benchmark: shorten pipe-to by reducing number of chunks 2023-09-13 19:44:44 +00:00
readable-async-iterator.js
readable-read-buffered.js stream: add fast paths for webstreams read and pipeTo 2026-02-19 21:53:46 +00:00
readable-read.js benchmark: add a benchmark for read() of ReadableStreams 2023-09-19 10:54:32 +00:00