stream: speed up flowing pipe of buffers · nodejs/node@26102c2 · GitHub
Skip to content

Commit 26102c2

Browse files
anonrigaduh95
authored andcommitted
stream: speed up flowing pipe of buffers
flow() pulls one already-buffered chunk and calls _read() for the next one on every iteration. That goes through the general read() path, which updates a holey buffer array and then pulls the chunk back out. While a synchronous byte-mode flow is in progress, keep that prefetched chunk on the readable state and emit it directly. _read() of the next chunk still runs before 'data', and a nested read() moves the chunk back onto the buffer. benchmark/streams/pipe.js is about 77% faster (15 runs). pipe-object-mode, readable-readall, and readable-bigread stay within noise. Assisted-by: a closed-source coding agent Signed-off-by: Yagiz Nizipli <yagiz@nizipli.com> PR-URL: #66182 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day> Reviewed-By: Zeyu "Alex" Yang <himself65@outlook.com>
1 parent 605938e commit 26102c2

2 files changed

Lines changed: 126 additions & 2 deletions

File tree

‎lib/internal/streams/destroy.js‎

Lines changed: 1 addition & 0 deletions

‎lib/internal/streams/readable.js‎

Lines changed: 125 additions & 2 deletions

0 commit comments

Comments
 (0)