Skip to content

Commit 6c53ddb

Browse files
trivikraduh95
authored andcommitted
stream: optimize single-slot push queue drain
Avoid allocating a new result array when PushQueue drains a single queued slot. Return that slot directly and keep the existing flattening path for multiple queued slots. Signed-off-by: Kamat, Trivikram <16024985+trivikr@users.noreply.github.com> Assisted-by: openai:gpt-5.5 PR-URL: #63274 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ethan Arrowood <ethan@arrowood.dev>
1 parent c4fb894 commit 6c53ddb

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
@@ -448,6 +448,10 @@ class PushQueue {
448448
// ===========================================================================
449449

450450
#drain() {
451+
if (this.#slots.length === 1) {
452+
return this.#slots.shift();
453+
}
454+
451455
const result = [];
452456
for (let i = 0; i < this.#slots.length; i++) {
453457
const slot = this.#slots.get(i);

0 commit comments

Comments
 (0)