perf: parallelise SampleEvaluations across (query, tree)#11
Closed
gbotrel wants to merge 1 commit into
Closed
Conversation
SampleEvaluations was the largest serial chunk left after the AIR / DEEP / evals-at-zeta parallelisation (15% of tall wall, 8% of wide). pprof showed only ~1 % of CPU sampled there: ~1 core busy for ~830 ms. The two nested loops (queries × trees) are fully independent — disjoint output slots in pr.Proof.PointSamplings, read-only access to allTrees, openingSources and the (internally locked) domainCache. Flatten them into a single NQ * NumTrees task list and parallel.Execute across it. Numbers, 32-core EPYC 9R45, synth (100M cells), median of 3: shape before after speedup tall (2^22 × 24) 5.55 s 4.63 s 1.20× wide (2^16 × 1536) 1.25 s 1.20 s 1.04× Phase breakdown — fri-query-open: tall 830 ms → 146 ms 5.7× wide 100 ms → 26 ms 3.8× The cumulative wall-time delta in `prove wall` doesn't sum to the fri-query-open delta because the kept-allocated weightCache (per rawLeaf call, not shared) means each goroutine pays the cache-miss cost once — already-cold cache before; cold cache per goroutine now. The weights are only ever ~2 keys per rawLeaf so the cache miss cost is negligible per task; total parallelism wins comfortably. Tests: full ./... suite + go test -race ./prover pass. Every existing prover end-to-end test exercises Verify after Prove — any reordering or duplicate writes in PointSamplings would surface there. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR broadens prover parallelism and benchmarking around the proving hot path, including the stated SampleEvaluations fan-out plus additional quotient, FRI, Merkle, commitment, and benchmarking changes.
Changes:
- Parallelizes several prover/PCS paths: sample openings, evaluations at zeta, quotient FFT loops, DEEP quotient accumulation, FRI folding, Merkle internal nodes, and commitment encoding/leaf hashing.
- Adds phase timing callbacks and a synthetic benchmark/profiling command.
- Adds
PowUint64, parallel helper utilities, FFT task-budget plumbing, and benchmark coverage for tall/wide proving shapes.
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
prover/prover.go |
Adds phase timing, parallel zeta evaluation, DEEP quotient rewrite, FFT task budgeting, and parallel sample openings. |
prover/bench_deep_quotient_test.go |
Adds tall/wide prover benchmarks over synthetic AIR inputs. |
plan_optims.md |
Adds optimization roadmap and measurement instructions. |
internal/reedsolomon/rs.go |
Allows encoder FFT options to be forwarded. |
internal/poly/utils.go |
Adds binary exponentiation helper for chunk seeding. |
internal/poly/utils_test.go |
Tests PowUint64. |
internal/poly/ext.go |
Allows evaluation helpers to forward FFT options. |
internal/poly/compute_quotient.go |
Parallelizes quotient FFT/division and coset conversion loops. |
internal/parallel/parallel.go |
Adds task-budget and thresholded execution helpers. |
internal/merkle/tree.go |
Parallelizes Merkle internal-node construction by level. |
internal/fri/fri.go |
Uses parallel leaf hashing and parallelizes FRI folding. |
internal/commitment/commitment.go |
Parallelizes RS encoding and exposes shared parallel leaf hashing. |
bench/synth/main.go |
Adds configurable synthetic prover benchmark with profiling and phase timing. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+21
to
+29
| // NbTasksPerJob divides the available CPU budget evenly across nbJobs running | ||
| // in parallel: it returns max(1, NumCPU/nbJobs). Use it to set per-job | ||
| // parallelism (e.g. fft.WithNbTasks) so that outer × inner goroutines stays | ||
| // near NumCPU instead of multiplying. | ||
| func NbTasksPerJob(nbJobs int) int { | ||
| if nbJobs <= 1 { | ||
| return runtime.NumCPU() | ||
| } | ||
| n := runtime.NumCPU() / nbJobs |
Comment on lines
+7
to
+8
| | tall (2²² × 24) | **5.55 s** | 1184 % (~11.8) | P3 1.56 s → P3 1.15× faster | | ||
| | wide (2¹⁶ × 1536) | **1.25 s** | 675 % (~6.7) | P3 0.40 s → **loom 1.4× faster** | |
Comment on lines
+718
to
+725
| // deepQuotientBundle aggregates everything needed to add one DEEP-quotient | ||
| // shift block's contribution to deepQuotient[*]: | ||
| // | ||
| // deepQuotient[x] += (vs - sum_k(scales_k * cols_k[x])) / (zs - omega^x) | ||
| // | ||
| // The serial alpha-power chain in the original code is unrolled into the | ||
| // scales slices below, so the per-row loop has no cross-column data dependency | ||
| // and can be chunked across goroutines. |
Comment on lines
+896
to
+902
| func accumulateDeepQuotient(deepQuotient poly.ExtPolynomial, bundles []deepQuotientBundle, domain *fft.Domain) { | ||
| N := len(deepQuotient) | ||
| if N == 0 || len(bundles) == 0 { | ||
| return | ||
| } | ||
|
|
||
| parallel.Execute(N, func(start, end int) { |
Comment on lines
+343
to
+350
| parallel.Execute(len(baseNonConst), func(start, end int) { | ||
| for k := start; k < end; k++ { | ||
| pCopy := baseNonConst[k] | ||
| smallDomain.FFTInverse(pCopy, fft.DIF, fftOpt) | ||
| scaleBaseByTwiddles(pCopy, twiddleFrMultiplicativeGen) | ||
| } | ||
| }) | ||
| parallel.Execute(len(extNonConst), func(start, end int) { |
Comment on lines
+151
to
+157
| parallel.Execute(len(piNonConst), func(start, end int) { | ||
| for k := start; k < end; k++ { | ||
| pCopy := piNonConst[k] | ||
| smallDomain.FFTInverse(pCopy, fft.DIF, fftOpt) | ||
| scaleByTwiddles(pCopy, twiddleFrMultiplicativeGen) | ||
| } | ||
| }) |
Collaborator
|
👍 cherry picked 7d0cd84 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Step 2 of `plan_optims.md`. `SampleEvaluations` was the largest serial chunk left after PRs #7/#8/#9 (15% of tall wall on 100M-cell trace, 8% of wide). pprof showed ~1% of CPU sampled there — i.e. ~1 core busy for ~830 ms.
The two nested loops (queries × trees) are fully independent: disjoint output slots in `pr.Proof.PointSamplings`, read-only access to `allTrees`, `openingSources`, and the internally-locked `domainCache`. Flatten them into `NQ × NumTrees` and `parallel.Execute` across the flat list.
Numbers
32-core EPYC 9R45, synth bench at 100 M cells, median of 3:
`fri-query-open` phase:
Test plan
🤖 Generated with Claude Code
Note
Cursor Bugbot is generating a summary for commit 7d0cd84. Configure here.