wasm build resolves miden-precompiles-prover without std, rebuilding the preprocessed table on every proof
- Vorherrschende Sprache
- TypeScript
- Sterne
- 1
- Forks
- 21
- Ø Merge
- 12 Std. 14 Min.
- Gemergte PRs (30 T.)
- 41
Beschreibung
> **This issue is written for coding agents.** It front-loads the exact code, an empirical verification recipe (because the obvious tool lies here), and machine-checkable acceptance criteria instead of narrative.
## Summary
In the wasm32 build of `miden-client-web`, `miden-precompiles-prover` resolves with its **`std` feature OFF**. That feature is what selects the *cached* preprocessed table. Without it, every proof that raises a precompile claim **rebuilds the preprocessed table from scratch** instead of reusing a process-lifetime `OnceLock`.
The table is a compile-time constant in all but name. Rebuilding it per proof is pure waste, and it is waste that only browsers pay — every native build has `std`.
## The code
miden-vm, `crates/precompiles-prover/src/session/preprocessed_cache.rs`, macro `cached_preprocessed!`:
```rust
#[cfg(feature = "std")]
{
static CACHE: std::sync::OnceLock> = std::sync::OnceLock::new();
PreprocessedHandle::Cached(CACHE.get_or_init(|| build(config))) // built once per process
}
#[cfg(not(feature = "std"))]
{
PreprocessedHandle::Owned(build(config)) // built EVERY call
}
```
## Why `std` is off
miden-vm's root `Cargo.toml` declares the crate with `default-features = false`:
```toml
miden-precompiles-prover = { path = "./crates/precompiles-prover", version = "0.29", default-features = false }
```
`std` then reaches it only via `miden-prover/std` or `miden-verifier/std` (see `prover/Cargo.toml`, `verifier/Cargo.toml`). The web-client's dependency chain enables neither.
## How to verify — **do not trust `cargo tree` here**
`cargo tree -e features` reports misleading feature sets in this workspace. It reports `miden-processor` *without* `std` even though `std` is demonstrably on for it (the `#[cfg(feature = "std")]`-only symbol `execute_and_build_trace_sync` is present in the shipped wasm). Do not use it as evidence either way.
Check the **binary** instead. `std` gates `dep:miden-ace-codegen`, so ace-codegen symbols are a direct proxy for the feature:
```bash
W=target/wasm32-unknown-unknown/release/miden_client_web.wasm
strings -a "$W" | grep -c ace_codegen # 0 => std OFF (current state)
strings -a "$W" | grep -c preprocessed_cache # 72 => module IS linked, so this path runs
strings -a "$W" | grep -c precompiles_prover # 11264
```
Those are the numbers on the current build. After a correct fix the first count must be non-zero.
## Impact — currently **UNMEASURED**. Size it before fixing.
Being explicit so nobody over-claims: we have established the *structural* defect, not its cost. Please measure first and put the numbers in the PR.
Scope of the cost:
- Per proof, not per client — the `OnceLock` is process-lifetime, so with `std` only the first proof pays.
- Only for proofs that **raise a precompile claim**. `prove_deferred_state` returns `DeferredProof::Empty` immediately when none are raised, so those proofs never touch this path at all. A wallet transaction authenticated with an ECDSA hot key does raise one; a plain CLI mint does not.
- Browser-only.
Suggested sizing, cheapest first:
1. Run two proofs **in the same client instance** and compare. With the cache, proof 2 should drop by the table-build cost; without it, both pay it. A large proof-1/proof-2 delta that *disappears* when `std` is forced on is the measurement.
2. Or build once with the feature forced on, once without, and diff the wall/CPU time of a single precompile-raising proof.
## Fix options
**1. Fix it in web-sdk (fastest).** Enable `std` for `miden-precompiles-prover` (and/or `miden-prover`) in the wasm build.
⚠️ Verify this does not drag in other `std`-gated paths that are wrong for wasm. There is a known one: `miden-processor`'s threaded trace build is gated on `#[cfg(feature = "std")]` and **traps on wasm** because wasm32 has `std` but cannot spawn threads. It is already reachable in the current build and is being fixed upstream, but it is exactly the class of surprise to check for before widening `std`.
**2. Fix it upstream in miden-vm (better).** Make the `no_std` branch cache as well — e.g. `spin::Once`. The `std` half already landed in v0.28.0; this just closes the gap for every `no_std` consumer instead of one.
Prefer **2** if upstream is responsive, since it fixes this for all embedders; **1** unblocks browsers immediately and the two are not exclusive.
## Acceptance criteria
- [ ] Before/after measurement of a precompile-raising proof in a browser, published in the PR. If the win is negligible, say so and close — that is a valid outcome.
- [ ] `strings -a miden_client_web.wasm | grep -c ace_codegen` is non-zero after the change (or, if fixed via option 2, a second proof in the same instance no longer pays the table build).
- [ ] A second proof in the same client instance does not rebuild the table.
- [ ] No new `std`-gated wasm-hostile path becomes reachable — in particular confirm the threaded trace-build situation is unchanged or already fixed.
Beitragsleitfaden
Rechercherichtung
Examine the dependency chain in the web-sdk workspace, focusing on Cargo.toml files for miden-precompiles-prover and its std feature. Verify the current state by analyzing the built WASM binary for ace_codegen symbols. Measure performance impact by running two proofs in the same client instance before and after enabling the std feature. Ensure no new std-gated, wasm-hostile paths become reachable, particularly checking the threaded trace build in miden-processor.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- rust, typescript, wasm
- Bereich
- backend, performance, web-dev
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Aktiv
- Klarheit
- Klar beschrieben
- Anfängerfreundlichkeit
- 45/100