Skip to content

Commit 06e0af2

Browse files
feat: add precomputed-tables for improved performance
- Add k256 precomputed-tables feature for faster elliptic curve operations - Provide custom critical-section implementation for WASM (single-threaded no-op) - Restore benchmark test to 1000 iterations Performance improvements: - derivePath from xpub: ~2x faster than utxo-lib - derive single child: ~2.2x faster than utxo-lib - fromBase58 (xpub): ~3x faster than utxo-lib
1 parent 44b4683 commit 06e0af2

4 files changed

Lines changed: 40 additions & 4 deletions

File tree

packages/wasm-bip32/Cargo.lock

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/wasm-bip32/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ k256 = { version = "0.13", default-features = false, features = [
2020
"ecdsa",
2121
"sha256",
2222
"alloc",
23+
"precomputed-tables",
24+
"critical-section",
2325
] }
2426
sha2 = { version = "0.10", default-features = false }
2527
ripemd = { version = "0.1", default-features = false }
@@ -28,6 +30,8 @@ bs58 = { version = "0.5", default-features = false, features = [
2830
"alloc",
2931
] }
3032
getrandom = { version = "0.2", features = ["js"] }
33+
# Provide critical-section implementation for WASM (single-threaded, so no-op)
34+
critical-section = "1.2"
3135

3236
[dev-dependencies]
3337
wasm-bindgen-test = "0.3"

packages/wasm-bip32/src/lib.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,19 @@ mod message;
66
pub use bip32::WasmBIP32;
77
pub use ecpair::WasmECPair;
88
pub use error::WasmBip32Error;
9+
10+
// Provide a no-op critical section implementation for single-threaded WASM
11+
use critical_section::RawRestoreState;
12+
13+
struct SingleThreadedCs;
14+
critical_section::set_impl!(SingleThreadedCs);
15+
16+
unsafe impl critical_section::Impl for SingleThreadedCs {
17+
unsafe fn acquire() -> RawRestoreState {
18+
// WASM is single-threaded, no actual locking needed
19+
}
20+
21+
unsafe fn release(_restore_state: RawRestoreState) {
22+
// WASM is single-threaded, no actual unlocking needed
23+
}
24+
}

packages/wasm-bip32/test/bip32.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,8 @@ describe("WasmBIP32", () => {
138138
});
139139
});
140140

141-
describe("BIP32 Benchmarks: wasm-bip32 vs utxo-lib", function () {
142-
// Increase timeout for benchmark tests (default mocha timeout is 2000ms)
143-
this.timeout(30000);
144-
const ops = 100;
141+
describe("BIP32 Benchmarks: wasm-bip32 vs utxo-lib", () => {
142+
const ops = 1000;
145143
const seed = new Uint8Array(32).fill(1);
146144
const xprv =
147145
"xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi";

0 commit comments

Comments
 (0)