From db76c2fc60ae4eff743ffd980dfce7fd83c55508 Mon Sep 17 00:00:00 2001 From: James M Snell Date: Sun, 4 Oct 2026 06:18:09 +0000 Subject: [PATCH] stream: read stream/iter push() readables without normalizing The readable of push() yields batches that it has validated already, but from(), and so pipeTo(), normalized them again through another async iterator layer. Mark the readable with kValidatedSource, as for Readable sources, so that they are read directly. Piping a push() stream written with 64 KiB chunks is about 30% faster. Assisted-by: OpenCode Signed-off-by: James M Snell PR-URL: https://github.com/nodejs/node/pull/66504 Reviewed-By: Matteo Collina Reviewed-By: Trivikram Kamat --- lib/internal/streams/iter/push.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/internal/streams/iter/push.js b/lib/internal/streams/iter/push.js index 8b6eb2da536..f5d5e38f006 100644 --- a/lib/internal/streams/iter/push.js +++ b/lib/internal/streams/iter/push.js @@ -26,6 +26,7 @@ const { const { drainableProtocol, + kValidatedSource, } = require('internal/streams/iter/types'); const { @@ -734,6 +735,9 @@ class PushWriter { function createReadable(queue) { return { __proto__: null, + // The batches read are validated already: from() and pipeTo() can read + // them without normalizing them again. + [kValidatedSource]: true, [SymbolAsyncIterator]() { return ObjectSetPrototypeOf({ async next() {