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: https://github.com/nodejs/node/pull/63274
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ethan Arrowood <ethan@arrowood.dev>
This commit is contained in:
Trivikram Kamat authored and GitHub committed 2026-05-15 20:03:17 +00:00
1 parent e5686734ee
commit be7ded1693
1 file changed
+4
+4
View File
@@ -448,6 +448,10 @@ class PushQueue {
// ===========================================================================
#drain() {
if (this.#slots.length === 1) {
return this.#slots.shift();
}
const result = [];
for (let i = 0; i < this.#slots.length; i++) {
const slot = this.#slots.get(i);