Skip to content

Uniform table cap + Twiddle dedup + FRI fold parallelism#497

Closed
gabrielbosio wants to merge 5 commits into
mainfrom
perf/prover-tables-fri-alloc
Closed

Uniform table cap + Twiddle dedup + FRI fold parallelism#497
gabrielbosio wants to merge 5 commits into
mainfrom
perf/prover-tables-fri-alloc

Conversation

@gabrielbosio

Copy link
Copy Markdown
Collaborator

No description provided.

Comment thread crypto/stark/src/prover.rs
Comment thread prover/src/tables/mod.rs
Comment thread crypto/stark/src/prover.rs Outdated
@gabrielbosio
gabrielbosio force-pushed the perf/prover-tables-fri-alloc branch from be10f79 to 40aad85 Compare April 14, 2026 20:33
Tables with effective width < 42 were sized at 2^21, producing single
large chunks. Capping at 2^20 produces 2x more chunks of the standard
size, improving parallel throughput and keeping peak memory per chunk
uniform across all tables.
Tables sharing the same lde_size now reuse a single Arc<LdeTwiddles>
instead of each allocating their own copy. This avoids redundant twiddle
computation and allocation when multiple tables happen to have the same
trace length (e.g., all 2^19-row tables after the cap change).
Under the `parallel` feature, fold each conjugate pair concurrently
using `par_chunks(2).zip(inv_twiddles.par_iter())`, collecting into a
new Vec of half length. The sequential path (no `parallel` feature) is
unchanged. This avoids the index aliasing issue from an in-place
interleaved write.
Replace the per-row `Vec` allocation inside the iterator with a
thread-local buffer via Rayon's `map_init` (parallel path) or a single
buffer allocated outside the loop (sequential path). This avoids one
heap allocation per row during Merkle tree construction.
@gabrielbosio
gabrielbosio force-pushed the perf/prover-tables-fri-alloc branch from 40aad85 to cf1c8d9 Compare April 14, 2026 20:46
@yetanotherco yetanotherco deleted a comment from claude Bot Apr 14, 2026
@yetanotherco yetanotherco deleted a comment from github-actions Bot Apr 14, 2026
@gabrielbosio

Copy link
Copy Markdown
Collaborator Author

/bench

@github-actions

github-actions Bot commented Apr 14, 2026

Copy link
Copy Markdown

Benchmark — fib_iterative_8M (median of 3)

Table parallelism: 32 (auto = cores / 3)

Metric main PR Δ
Peak heap 221071 MB 125861 MB -95210 MB (-43.1%) 🟢
Prove time 46.720s 45.755s -0.965s (-2.1%) ⚪

🎉 Improvement detected — heap or time decreased by more than 5%.

✅ Low variance (time: 1.5%, heap: 0.4%)

Commit: eeb860c · Baseline: built from main · Runner: self-hosted bench

@gabrielbosio
gabrielbosio force-pushed the perf/prover-tables-fri-alloc branch from cf1c8d9 to 4fec818 Compare April 14, 2026 21:40
@gabrielbosio

Copy link
Copy Markdown
Collaborator Author

/bench

@gabrielbosio

Copy link
Copy Markdown
Collaborator Author

Capping 2^20 is not showing a difference against capping 2^19.

@gabrielbosio
gabrielbosio marked this pull request as ready for review April 14, 2026 21:54
@gabrielbosio
gabrielbosio force-pushed the perf/prover-tables-fri-alloc branch from 4fec818 to cf1c8d9 Compare April 14, 2026 21:57
Comment thread crypto/stark/src/fri/fri_functions.rs Outdated
&sum + &(&inv_twiddles[j] * &(zeta * &diff))
})
.collect();
*evals = folded;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Low – parallel path always allocates a fresh Vec per fold level

*evals = folded drops the old allocation and replaces it. FRI folding runs ~log₂(N) times on the hot path, so this adds ~log₂(N) allocations compared to the sequential path.

One option is to reuse the buffer:

Suggested change
*evals = folded;
evals.clear();
evals.extend(folded);

Or pass in a mutable scratch buffer so the caller can pre-allocate once and reuse across levels. The current approach is correct but leaves a performance opportunity on the table given this is the inner loop of FRI.

Comment thread prover/src/tables/mod.rs
@gabrielbosio

Copy link
Copy Markdown
Collaborator Author

/bench

@gabrielbosio
gabrielbosio force-pushed the perf/prover-tables-fri-alloc branch from 2386f19 to eeb860c Compare April 15, 2026 17:47
@gabrielbosio

Copy link
Copy Markdown
Collaborator Author

/bench

@gabrielbosio

Copy link
Copy Markdown
Collaborator Author

#499 showed the same improvement and it's smaller.

@gabrielbosio
gabrielbosio deleted the perf/prover-tables-fri-alloc branch April 20, 2026 18:15
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.

2 participants