@nxtedition/slice
Advanced tools
+2
-2
| { | ||
| "name": "@nxtedition/slice", | ||
| "version": "1.0.7", | ||
| "version": "1.0.8", | ||
| "type": "module", | ||
@@ -31,3 +31,3 @@ "main": "lib/index.js", | ||
| }, | ||
| "gitHead": "8dbd8386c6d4c511ffa81a904c58b6f648811a52" | ||
| "gitHead": "12c38fec15bd155797cb1edae372a81061715df3" | ||
| } |
+29
-17
@@ -48,25 +48,37 @@ # @nxtedition/slice | ||
| | Operation | `Buffer.allocUnsafe` | `Buffer.allocUnsafeSlow` | `PoolAllocator` | Speedup | | ||
| | ---------------- | -------------------- | ------------------------ | --------------- | ------- | | ||
| | alloc 64 bytes | 28.53 ns | 31.33 ns | **3.87 ns** | 7.4x | | ||
| | alloc 256 bytes | 36.98 ns | 170.56 ns | **4.34 ns** | 8.5x | | ||
| | alloc 1024 bytes | 65.48 ns | 238.49 ns | **4.36 ns** | 15.0x | | ||
| | alloc 4096 bytes | 301.19 ns | 292.50 ns | **4.29 ns** | 70.2x | | ||
| | ---------------- | -------------------: | -----------------------: | --------------: | ------: | | ||
| | alloc 64 bytes | 38.08 ns | 41.23 ns | **5.66 ns** | 6.7x | | ||
| | alloc 256 bytes | 52.09 ns | 231.46 ns | **5.90 ns** | 8.8x | | ||
| | alloc 1024 bytes | 91.24 ns | 340.75 ns | **5.83 ns** | 15.6x | | ||
| | alloc 4096 bytes | 446.53 ns | 437.83 ns | **6.24 ns** | 71.6x | | ||
| ### Allocation (GC) | ||
| | Operation | `Buffer.allocUnsafe` | `Buffer.allocUnsafeSlow` | `PoolAllocator` | Speedup | | ||
| | ---------------- | -------------------: | -----------------------: | --------------: | ------: | | ||
| | alloc 64 bytes | 400.46 ns | 167.94 ns | **6.33 ns** | 63.3x | | ||
| | alloc 256 bytes | 309.57 ns | 500.58 ns | **6.35 ns** | 48.7x | | ||
| | alloc 4096 bytes | 653.40 ns | 620.19 ns | **6.32 ns** | 103.4x | | ||
| Under GC pressure, the advantage grows dramatically — up to **103x** faster — because `PoolAllocator` reuses slots from a pre-allocated buffer and never creates objects for V8 to trace. | ||
| ### Slice creation vs `Buffer.subarray` | ||
| | Operation | `Buffer.subarray` | `Slice` | Speedup | | ||
| | ------------------- | ----------------- | ----------- | ------- | | ||
| | subarray 64 bytes | 27.32 ns | **9.68 ns** | 2.8x | | ||
| | subarray 1024 bytes | 26.75 ns | **9.52 ns** | 2.8x | | ||
| | Operation | `Buffer.subarray` | `Slice` | Speedup | | ||
| | ---------------------- | ----------------: | -----------: | ------: | | ||
| | subarray 64 bytes | 38.11 ns | **12.99 ns** | 2.9x | | ||
| | subarray 1024 bytes | 36.87 ns | **13.26 ns** | 2.8x | | ||
| | subarray 64 bytes (GC) | 127.30 ns | **81.60 ns** | 1.6x | | ||
| ### Combined operations | ||
| | Operation | `Buffer.subarray` | `Slice` | Speedup | | ||
| | ------------------------------------- | ----------------- | ------------- | ------- | | ||
| | subarray + toString (64 bytes) | 78.89 ns | **60.12 ns** | 1.3x | | ||
| | alloc/free 64 bytes | 25.24 ns | **22.82 ns** | 1.1x | | ||
| | alloc/free 256 bytes | 34.07 ns | **22.63 ns** | 1.5x | | ||
| | realloc churn (64 → 128 → 64) | 70.20 ns | **20.80 ns** | 3.4x | | ||
| | realloc in-place (grow within bucket) | 45.41 ns | **8.28 ns** | 5.5x | | ||
| | 10 concurrent allocs then free | 312.96 ns | **259.34 ns** | 1.2x | | ||
| | Operation | `Buffer` | `PoolAllocator` | Speedup | | ||
| | ------------------------------------- | --------: | --------------: | ------: | | ||
| | alloc/free 64 bytes | 32.72 ns | **30.80 ns** | 1.1x | | ||
| | alloc/free 64 bytes (GC) | 273.35 ns | **73.34 ns** | 3.7x | | ||
| | alloc/free 256 bytes | 58.88 ns | **29.38 ns** | 2.0x | | ||
| | realloc churn (64 → 128 → 64) | 93.63 ns | **26.99 ns** | 3.5x | | ||
| | realloc in-place (grow within bucket) | 60.16 ns | **11.06 ns** | 5.4x | | ||
| | 10 concurrent allocs then free | 406.26 ns | **337.83 ns** | 1.2x | | ||
| | 10 concurrent allocs then free (GC) | 647.95 ns | **649.73 ns** | 1.0x | | ||
@@ -73,0 +85,0 @@ ## API |
19708
4.4%139
9.45%