Files
bun.sh/bench/snippets
SUZUKI Sosuke f01467d3dc perf(buffer): optimize Buffer.from(array) by using setFromArrayLike directly (#26135)
## Summary

Optimizes `Buffer.from(array)` by bypassing `JSC::construct()` overhead
(~30ns) and leveraging JSC's internal array optimizations.

## Changes

- For JSArray inputs, directly use `setFromArrayLike()` which internally
detects array indexing types (Int32Shape/DoubleShape) and uses bulk copy
operations (`copyFromInt32ShapeArray`/`copyFromDoubleShapeArray`)
- Array-like objects and iterables continue to use the existing slow
path
- Added mitata benchmark for measuring performance

## Benchmark Results

| Test | Before | After | Improvement |
|------|--------|-------|-------------|
| Buffer.from(int32[8]) | ~85ns | ~43ns | ~50% faster |
| Buffer.from(int32[64]) | ~207ns | ~120ns | ~42% faster |
| Buffer.from(int32[1024]) | ~1.85μs | ~1.32μs | ~29% faster |
| Buffer.from(double[8]) | ~86ns | ~50ns | ~42% faster |
| Buffer.from(double[64]) | ~212ns | ~151ns | ~29% faster |

Bun is now faster than Node.js for these operations.

## Test

All 449 buffer tests pass.
2026-01-15 12:10:47 -08:00
..
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2023-03-02 19:02:10 -08:00
2024-11-08 23:15:24 -08:00
2025-02-12 23:37:36 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2025-02-16 00:42:05 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2025-07-10 00:10:43 -07:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2025-03-10 20:19:29 -07:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2025-06-03 03:34:35 -07:00
2024-11-08 23:15:24 -08:00
2022-12-06 14:18:25 -08:00
2022-12-06 14:18:25 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2025-02-12 23:14:02 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2025-04-08 03:57:35 -07:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2024-11-08 23:15:24 -08:00
2024-12-24 04:20:24 -08:00