-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: use Buffer.concat on node as it is faster #73
Conversation
Running the concat.js benchmark: Before: ``` Uint8Arrays.concat x 792,619 ops/sec ±0.67% (98 runs sampled) Uint8Arrays.concat with length x 782,264 ops/sec ±0.18% (98 runs sampled) Uint8Array.set x 799,528 ops/sec ±0.67% (92 runs sampled) allocUnsafe.set x 851,403 ops/sec ±0.24% (97 runs sampled) Fastest is allocUnsafe.set ``` After: ``` Uint8Arrays.concat x 896,831 ops/sec ±0.20% (101 runs sampled) Uint8Arrays.concat with length x 887,523 ops/sec ±0.19% (99 runs sampled) Uint8Array.set x 814,749 ops/sec ±0.46% (98 runs sampled) allocUnsafe.set x 885,140 ops/sec ±0.28% (98 runs sampled) Fastest is Uint8Arrays.concat ```
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #73 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 16 16
Lines 554 547 -7
Branches 93 82 -11
=========================================
- Hits 554 547 -7
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
## [4.0.9](v4.0.8...v4.0.9) (2023-11-24) ### Bug Fixes * use Buffer.concat on node as it is faster ([#73](#73)) ([8d6c24b](8d6c24b))
export function concat (arrays: Array<ArrayLike<number>>, length?: number): Uint8Array { | ||
export function concat (arrays: Uint8Array[], length?: number): Uint8Array { | ||
if (globalThis.Buffer != null) { | ||
return asUint8Array(globalThis.Buffer.concat(arrays, length)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately arrays
here causes Buffer.concat to throw
, where before arrays
would have been converted to a Uint8Array on line 24.
Reinstantes the performance changes from #73 BREAKING CHANGE: concat now expects an array of Uint8Arrays
Reinstates the performance changes from #73 BREAKING CHANGE: concat now expects an array of Uint8Arrays
Running the concat.js benchmark:
Before:
After: