Skip to content
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

Merged
merged 1 commit into from
Nov 24, 2023

Conversation

achingbrain
Copy link
Owner

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

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
```
Copy link

codecov bot commented Nov 24, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (2a9a0bf) 100.00% compared to head (0b64cd9) 100.00%.
Report is 1 commits behind head on master.

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     
Flag Coverage Δ
chrome 100.00% <100.00%> (ø)
node 90.12% <81.81%> (-6.63%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@achingbrain achingbrain merged commit 8d6c24b into master Nov 24, 2023
21 checks passed
@achingbrain achingbrain deleted the fix/use-buffer-concat-and-compate branch November 24, 2023 18:36
github-actions bot pushed a commit that referenced this pull request Nov 24, 2023
## [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))

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.

achingbrain added a commit that referenced this pull request Dec 7, 2023
Reinstantes the performance changes from #73

BREAKING CHANGE: concat now expects an array of Uint8Arrays
achingbrain added a commit that referenced this pull request Dec 7, 2023
Reinstates the performance changes from #73

BREAKING CHANGE: concat now expects an array of Uint8Arrays
github-actions bot pushed a commit that referenced this pull request Dec 7, 2023
## [5.0.0](v4.0.10...v5.0.0) (2023-12-07)

### ⚠ BREAKING CHANGES

* concat now expects an array of Uint8Arrays

### Features

* use buffer.concat in node ([#76](#76)) ([ea51546](ea51546)), closes [#73](#73)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants