Skip to content

Commit 3bc119f

Browse files
jasnelladuh95
authored andcommitted
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 <jasnell@gmail.com> PR-URL: #66504 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
1 parent 6d34354 commit 3bc119f

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

‎lib/internal/streams/iter/push.js‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const {
2626

2727
const {
2828
drainableProtocol,
29+
kValidatedSource,
2930
} = require('internal/streams/iter/types');
3031

3132
const {
@@ -734,6 +735,9 @@ class PushWriter {
734735
function createReadable(queue) {
735736
return {
736737
__proto__: null,
738+
// The batches read are validated already: from() and pipeTo() can read
739+
// them without normalizing them again.
740+
[kValidatedSource]: true,
737741
[SymbolAsyncIterator]() {
738742
return ObjectSetPrototypeOf({
739743
async next() {

0 commit comments

Comments
 (0)