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

Improve hexToBytes performance #83

Merged
merged 2 commits into from
Sep 13, 2023
Merged

Improve hexToBytes performance #83

merged 2 commits into from
Sep 13, 2023

Conversation

arobsn
Copy link
Contributor

@arobsn arobsn commented Sep 13, 2023

What this does

Rewrites hexToBytes function using char code approach to gain ~6x in performance.

Benchmark

Benchmark results on a MacBook Air M1 and node v20:

 ✓ packages/crypto/src/coders/hex.bench.ts (6) 3583ms
   ✓ Decode hex to bytes (3) 3055ms
     name                                      hz     min     max    mean     p75     p99    p995    p999     rme  samples
   · @noble/hashes implementation       25,861.49  0.0364  0.4523  0.0387  0.0381  0.0433  0.0540  0.3573  ±0.67%    12931  
   · @scure/base implementation          4,391.03  0.2167  0.6890  0.2277  0.2287  0.2810  0.5655  0.6118  ±0.66%     2196   slowest
   · @fleet-sdk/crypto implementation  173,810.56  0.0054  0.4406  0.0058  0.0057  0.0076  0.0093  0.0144  ±0.31%    86906   fastest

  @fleet-sdk/crypto implementation - packages/crypto/src/coders/hex.bench.ts > Decode hex to bytes
    6.72x faster than @noble/hashes implementation
    39.58x faster than @scure/base implementation

Benchmark code: https://github.com/fleet-sdk/fleet/blob/master/packages/crypto/src/coders/hex.bench.ts

@paulmillr
Copy link
Owner

This is awesome. Thanks @arobsn

@paulmillr paulmillr merged commit 728b485 into paulmillr:main Sep 13, 2023
2 checks passed
@paulmillr
Copy link
Owner

Also landed in noble-hashes at paulmillr/noble-hashes@84f9cf6

@paulmillr
Copy link
Owner

@arobsn
Copy link
Contributor Author

arobsn commented Sep 13, 2023

Awesome, thanks for merging! I'm a big fan of your work :)

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.

None yet

2 participants