Skip to content

Add WASM Merkle proof benchmark - #188

Closed
dicethedev wants to merge 8 commits into
NethermindEth:mainfrom
dicethedev:benchmark/merkle-prefix-tree-wasm
Closed

Add WASM Merkle proof benchmark#188
dicethedev wants to merge 8 commits into
NethermindEth:mainfrom
dicethedev:benchmark/merkle-prefix-tree-wasm

Conversation

@dicethedev

@dicethedev dicethedev commented Apr 29, 2026

Copy link
Copy Markdown

Summary

Moves the Merkle proof benchmark out of the web bundle and into the prover crate, following maintainer feedback on #167.

This PR adds a criterion benchmark under app/crates/core/prover/benches for the current append-only Merkle prefix tree flow:

  1. build MerklePrefixTreeBuilt from ordered leaves
  2. generate membership proofs from the built tree

It also removes the previously added Trunk/web benchmark wiring so the benchmark is not included in the app distribution.

What Changed

  • Added criterion bench: app/crates/core/prover/benches/merkle_prefix_tree.rs
  • Added bench docs: app/crates/core/prover/benches/README.md
  • Removed web benchmark export/page/staging
  • Removed app-level benchmark docs
  • Adjusted getrandom dependency wiring so browser WASM still uses js, while non-browser wasm targets are not forced into that feature path

Benchmark Results

Measured locally with:

cargo bench -p prover --bench merkle_prefix_tree

Build MerklePrefixTreeBuilt

Leaves Time
16 941–956 µs
64 1.537–1.582 ms
256 3.912–3.965 ms
1,024 13.734–14.056 ms
4,096 53.270–54.429 ms
16,384 208.16–209.91 ms

Generate Proof from Built Tree

Leaves Time
16 225.81–229.20 ns
64 234.15–239.59 ns
256 231.33–233.01 ns
1,024 234.94–238.54 ns
4,096 238.43–243.27 ns
16,384 242.81–244.62 ns

The native benchmark shows that tree build time grows with leaf count, while proof generation from a built tree remains effectively constant and extremely fast.

Browser Validation

The browser/WASI flow is documented in:

app/crates/core/prover/benches/README.md

Validated locally by:

  1. Building the benchmark for wasm32-wasip1
  2. Opening https://webassembly.sh/
  3. Running wapm upload
  4. Uploading target/wasm32-wasip1/release/deps/merkle_prefix_tree-*.wasm
  5. Running the installed command in the browser shell

Observed Result

merkle_prefix_tree_build/16 through merkle_prefix_tree_build/16384 reported Success

merkle_prefix_tree_proof/16 through merkle_prefix_tree_proof/16384 reported Success

In the browser shell run, all benchmark cases completed successfully, although timing information was not printed in the terminal output.

Verification

cargo test -p prover merkle::tests --lib
cargo bench -p prover --bench merkle_prefix_tree --no-run
cargo bench -p prover --bench merkle_prefix_tree
cargo bench -p prover --bench merkle_prefix_tree --target wasm32-wasip1 --no-run
cargo fmt --check
git diff --check

Notes

  • Criterion emitted expected sampling warnings for larger input sizes because 100 samples could not fit within the default 5-second target time.
  • Benchmark correctness was validated on both native and WASI targets.

Closes #167

@maksimryndin

Copy link
Copy Markdown
Contributor

hey @dicethedev! ✋ thanks a lot for this measurement 🚀 . Could we make this code organization a bit different?

Basically, the benchmarks is related to the prover crate has only it as a dependency (except some JsValue but it is not critical). So naturally it should go to the prover crate (with some benches dir inside) and we could use https://criterion-rs.github.io/book/user_guide/wasi.html ?

And we don't need to put it in Trunk otherwise it will be in the distribution (and it is not needed)

@dicethedev

Copy link
Copy Markdown
Author

hey @dicethedev! ✋ thanks a lot for this measurement 🚀 . Could we make this code organization a bit different?

Basically, the benchmarks is related to the prover crate has only it as a dependency (except some JsValue but it is not critical). So naturally it should go to the prover crate (with some benches dir inside) and we could use https://criterion-rs.github.io/book/user_guide/wasi.html ?

And we don't need to put it in Trunk otherwise it will be in the distribution (and it is not needed)

Alright
I will make the suggested fixes

@dicethedev

Copy link
Copy Markdown
Author

@maksimryndin you can review again

@maksimryndin

Copy link
Copy Markdown
Contributor

@maksimryndin you can review again

Hey @dicethedev ! ✋ thanks a lot! A minor comment - our goal is to benchmark for native (which you already shared here) and a browser (which you did earlier 👍 but now you provided wasmtime which is not relevant here - could you please update the guide https://github.com/NethermindEth/stellar-private-payments/pull/188/changes#diff-0e4d2392353f348d546c0ec01bc7e65897023fb529245cbecdbaf6484bb0ce0bR19 for the use of a browser to benchmark like https://criterion-rs.github.io/book/user_guide/wasi.html#running-in-a-browser-with-webassemblysh and try to run it and publish the result here as well)?

Thank you!

@dicethedev

Copy link
Copy Markdown
Author

@maksimryndin you can review again

Hey @dicethedev ! ✋ thanks a lot! A minor comment - our goal is to benchmark for native (which you already shared here) and a browser (which you did earlier 👍 but now you provided wasmtime which is not relevant here - could you please update the guide https://github.com/NethermindEth/stellar-private-payments/pull/188/changes#diff-0e4d2392353f348d546c0ec01bc7e65897023fb529245cbecdbaf6484bb0ce0bR19 for the use of a browser to benchmark like https://criterion-rs.github.io/book/user_guide/wasi.html#running-in-a-browser-with-webassemblysh and try to run it and publish the result here as well)?

Thank you!

Alright. I will jump on the changes you mention.

@maksimryndin

Copy link
Copy Markdown
Contributor

hey @dicethedev! 🙌 could you pls tell us any plans here? I believe only a small doc change is needed?

@dicethedev

Copy link
Copy Markdown
Author

hey @dicethedev! 🙌 could you pls tell us any plans here? I believe only a small doc change is needed?

Yes. I will update it soon please

@dicethedev
dicethedev requested a review from cupicmarko as a code owner June 11, 2026 11:59
Comment thread app/crates/core/prover/benches/README.md Outdated
Comment thread app/crates/core/prover/benches/README.md Outdated
@maksimryndin maksimryndin mentioned this pull request Jun 30, 2026
5 tasks
@Fantoni0

Fantoni0 commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Closing as stale

@Fantoni0 Fantoni0 closed this Sep 1, 2026
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.

Explore efficient Merkle proof building

3 participants