Commit 86dd5c8
committed
lib: optimize writable stream buffer clearing
Improved the `clearBuffer` function in `lib/internal/streams/writable.js`
by replacing `buffered.splice(0, i)` with `ArrayPrototypeSlice(buffered, i)`.
This change eliminates the O(N) shifting overhead of `splice` when clearing
the buffer, especially for large buffers, leading to better CPU utilization
and reduced garbage collection overhead.
Profiling before and after the change showed a significant reduction in
10 CPU ticks attributed to the `clearBuffer` function, from 90 ticks to 1 tick.1 parent f3adc11 commit 86dd5c8
1 file changed
+1
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
784 | 784 | | |
785 | 785 | | |
786 | 786 | | |
787 | | - | |
| 787 | + | |
788 | 788 | | |
789 | 789 | | |
790 | 790 | | |
| |||
0 commit comments