Skip to content

Commit 8a8653d

Browse files
committed
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.
1 parent f3adc11 commit 8a8653d

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
@@ -784,7 +784,7 @@ function clearBuffer(stream, state) {
784784
if (i === buffered.length) {
785785
resetBuffer(state);
786786
} else if (i > 256) {
787-
buffered.splice(0, i);
787+
state[kBufferedValue] = ArrayPrototypeSlice(buffered, i);
788788
state.bufferedIndex = 0;
789789
} else {
790790
state.bufferedIndex = i;

0 commit comments

Comments
 (0)