Skip to content

perf(core)!: optimise interop with crypto wasm #248

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

Merged
merged 3 commits into from
Mar 14, 2025

Conversation

0x009922
Copy link
Contributor

@0x009922 0x009922 commented Mar 13, 2025

  • Use Rc inside PublicKey and PrivateKey to make cloning cheaper
  • Remove BytesJs, duplicate methods for bytes input and hex input (e.g. from_raw and from_raw_hex). Experiments showed this is faster.
  • Remove duplicate _hex getters (e.g. leave only payload, remove payload_hex). Experiments showed that getting data always as bytes and then optionally "hexing" it is faster than getting hex and then optionally "dehexing" it.

Misc:

  • Breaking: remove VerifyResult from Signature.verify(); just throw plain errors.

Closes #241

Benchmarks are confusing. Depending on the order of benches in the file, prev or next could be faster. In other words, this PR doesn't bring a noticeable change. But the source code on the Rust side is clearer now and maybe it will indeed work faster in some cases.

    CPU | AMD Ryzen 9 7950X 16-Core Processor
Runtime | Deno 2.2.3 (x86_64-unknown-linux-gnu)

file:///home/quacumque/Projects/iroha-javascript/packages/core/crypto/crypto.bench.ts

benchmark           time/iter (avg)        iter/s      (min … max)           p75      p99     p995
------------------- ----------------------------- --------------------- --------------------------

group hash
from hex                   771.1 ns     1,297,000 (587.3 ns …   4.2 µs) 779.2 ns   4.2 µs   4.2 µs
from hex (prev)              2.7 µs       368,300 (660.9 ns …  20.4 µs) 857.7 ns  20.4 µs  20.4 µs
from array                 953.6 ns     1,049,000 (767.2 ns …   2.2 µs) 922.0 ns   2.2 µs   2.2 µs
from array (prev)            8.3 µs       120,500 (787.5 ns … 112.2 µs)   1.0 µs 112.2 µs 112.2 µs

summary
  from hex
     1.24x faster than from array
     3.52x faster than from hex (prev)
    10.76x faster than from array (prev)

group kp-copy
new                         19.8 ms          50.6 (  2.4 ms …  52.4 ms)  31.6 ms  52.4 ms  52.4 ms
prev                        16.8 ms          59.5 (  2.5 ms … 217.8 ms)   5.2 ms 217.8 ms 217.8 ms

summary
  prev
     1.18x faster than new

group sign
new                        392.2 µs         2,550 (369.7 µs …   3.3 ms) 383.0 µs 941.9 µs   1.0 ms
prev                       384.0 µs         2,604 (368.4 µs …   1.2 ms) 380.1 µs 554.2 µs 904.2 µs

summary
  prev
     1.02x faster than new

@0x009922 0x009922 merged commit 77b7f11 into hyperledger-iroha:main Mar 14, 2025
5 checks passed
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.

Optimise crypto wasm
1 participant