mirror of
https://github.com/oven-sh/bun
synced 2026-02-02 15:08:46 +00:00
## 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.
npm install
bun run ffi
bun run log
bun run gzip
bun run async
bun run sqlite
# to use custom version of bun/deno/node binary
BUN=path/to/bun bun run ffi
# or edit .env file