Skip to content

Commit 263e8d9

Browse files
ri7116aduh95
authored andcommitted
lib: optimize writable stream buffer clearing
Improved the `clearBuffer` function by replacing `buffered.splice` with `ArrayPrototypeSlice`. - Eliminates O(N) shifting overhead. - Improves CPU utilization and reduces GC overhead. PR-URL: #59406 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Ethan Arrowood <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
1 parent 39c2f23 commit 263e8d9

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

lib/internal/streams/writable.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,7 @@ function clearBuffer(stream, state) {
786786
if (i === buffered.length) {
787787
resetBuffer(state);
788788
} else if (i > 256) {
789-
buffered.splice(0, i);
789+
state[kBufferedValue] = ArrayPrototypeSlice(buffered, i);
790790
state.bufferedIndex = 0;
791791
} else {
792792
state.bufferedIndex = i;

0 commit comments

Comments
 (0)