Commit e88373d
committed
buffer: always use _copy for copy
This fixes a performance regression for Buffer.copy(target, 0) and brings it back inline with Buffer.write.
V8 has a massive TypedArray.prototype.set penalty on SharedArrayBuffer
Buffer.set and Buffer.copy are up to 8.4x slower when writing to a SharedArrayBuffer vs a regular ArrayBuffer, while Buffer.write (string encoding) is completely unaffected.
256 bytes, varying offset (Apple M3 Pro, Node 25.6.1):
ArrayBuffer SharedArrayBuffer Slowdown
Buffer.set 13.6 ns 56.1 ns 4.1x
Buffer.copy 17.0 ns 65.1 ns 3.8x
Buffer.write 75.8 ns 74.1 ns 1.0x (unaffected)
4096 bytes, varying offset:
ArrayBuffer SharedArrayBuffer Slowdown
Buffer.set 80.3 ns 674.2 ns 8.4x
Buffer.copy 78.4 ns 677.7 ns 8.6x
Buffer.write 190.6 ns 186.1 ns 1.0x (unaffected)1 parent c9d0ef8 commit e88373d
1 file changed
+2
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
268 | 268 | | |
269 | 269 | | |
270 | 270 | | |
271 | | - | |
| 271 | + | |
272 | 272 | | |
273 | 273 | | |
274 | 274 | | |
| |||
280 | 280 | | |
281 | 281 | | |
282 | 282 | | |
283 | | - | |
284 | | - | |
285 | | - | |
286 | | - | |
287 | | - | |
| 283 | + | |
288 | 284 | | |
289 | 285 | | |
290 | 286 | | |
| |||
0 commit comments