mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 13:48:44 +02:00
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: https://github.com/nodejs/node/pull/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>
This commit is contained in:
parent
aac7925801
commit
8a2fec1f6f
1 changed files with 1 additions and 1 deletions
|
@ -784,7 +784,7 @@ function clearBuffer(stream, state) {
|
|||
if (i === buffered.length) {
|
||||
resetBuffer(state);
|
||||
} else if (i > 256) {
|
||||
buffered.splice(0, i);
|
||||
state[kBufferedValue] = ArrayPrototypeSlice(buffered, i);
|
||||
state.bufferedIndex = 0;
|
||||
} else {
|
||||
state.bufferedIndex = i;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue