Skip to content

Commit d2183d8

Browse files
ri7116RafaelGSS
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 <matteo.collina@gmail.com> Reviewed-By: Ethan Arrowood <ethan@arrowood.dev> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Anna Henningsen <anna@addaleax.net>
1 parent 7e10f95 commit d2183d8

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)