cryptocoinjs / hdkey

JavaScript component for Bitcoin hierarchical deterministic keys (BIP32)
MIT License
201 stars 74 forks source link

perf: allow skipping public key verification #53

Closed kewde closed 1 year ago

kewde commented 1 year ago

The public key verification is rather slower in a pure JS mode. This PR introduces an argument skipVerification to fromExtendedKey() to allow skipping the verification.$

builds on #52

I did some quick benchmarks for thisPR.

elliptic with BN.js: 8x performance increase with skipVerification set to true.

HDKey.fromExtendedKey(key) x 4,712 ops/sec ±4.69% (75 runs sampled)
HDKey.fromExtendedKey(key, null, true) x 39,627 ops/sec ±4.94% (71 runs sampled)
Fastest is HDKey.fromExtendedKey(key, null, true)

This allows fromExtendedKey to run just as quick as the native performance:

HDKey.fromExtendedKey(key) x 30,868 ops/sec ±4.71% (77 runs sampled)
HDKey.fromExtendedKey(key, null, true) x 38,105 ops/sec ±5.65% (67 runs sampled)
Fastest is HDKey.fromExtendedKey(key, null, true)
kewde commented 1 year ago

@RyanZim

RyanZim commented 1 year ago

https://github.com/cryptocoinjs/hdkey/pull/52 is merged; please rebase.

kewde commented 1 year ago

@RyanZim rebased

kewde commented 1 year ago

@RyanZim I think there's already a unit test included in the PR that covers it.

RyanZim commented 1 year ago

:man_facepalming: I had seen that earlier, but somehow missed it; must have been just reviewing a later commit.

RyanZim commented 1 year ago

Published in v2.1.0 :tada: