Skip to content

feat: add BB_POLY_STATS for prover polynomial memory analysis#20421

Merged
johnathan79717 merged 1 commit intomerge-train/barretenbergfrom
jh/poly-stats
Feb 12, 2026
Merged

feat: add BB_POLY_STATS for prover polynomial memory analysis#20421
johnathan79717 merged 1 commit intomerge-train/barretenbergfrom
jh/poly-stats

Conversation

@johnathan79717
Copy link
Contributor

Summary

Usage

BB_POLY_STATS=1 ./build/bin/chonk_bench --benchmark_filter=Full/2

Outputs a table like:

=== Polynomial Memory Analysis ===
Polynomial                           |  AllocSize |      Zeros |       <=4B |       <=8B |      <=16B |      <=32B |    Mem(MB) |  Compr(MB)
sigma_1                              |     336637 |          0 |     336629 |          0 |          0 |          8 |      10.27 |       1.28
w_l                                  |     336637 |      45462 |     165039 |      13556 |      76637 |      35943 |      10.27 |       3.00
...
TOTAL                                |    8125052 |    3192926 |    4004383 |     148196 |     318296 |     461251 |     247.96 |      35.34

Total actual memory:     247.96 MB
Total compressed memory: 35.34 MB
Potential savings:       85.7%

Initial findings (2^19 mock app circuit)

  • 85.7% theoretical savings with ideal variable-length encoding
  • Sigma/ID polys (8 polys, ~82 MB): 100% values fit in 4 bytes — uint32_t gives 8x compression
  • Wire polys (w_l–w_4, ~41 MB): ~50% fit in 4B, ~20% need full 32B
  • Selector polys (~96 MB): ~80% zeros, rest mostly small — already partially optimized via mega-selectors
  • z_perm, lookup_inverses (~11 MB): 100% zeros at construction time (filled later)

Test plan

  • Builds with cmake --build build --target chonk_bench
  • BB_POLY_STATS=1 ./build/bin/chonk_bench produces correct per-polynomial report
  • No output when BB_POLY_STATS is unset (zero overhead in normal operation)

…analysis

When the BB_POLY_STATS env var is set, prints a per-polynomial report after
ProverInstance construction showing value-size distribution (zeros, <=4B,
<=8B, <=16B, <=32B) and ideal compressed memory. Helps assess feasibility
of variable-length encoding for memory reduction.

Resolves AztecProtocol/barretenberg#1623
@johnathan79717 johnathan79717 added the ci-barretenberg Run all barretenberg/cpp checks. label Feb 12, 2026
Copy link
Contributor

@ledwards2225 ledwards2225 left a comment

Choose a reason for hiding this comment

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

Very cool!

@johnathan79717 johnathan79717 merged commit 30aa0ef into merge-train/barretenberg Feb 12, 2026
16 of 18 checks passed
@johnathan79717 johnathan79717 deleted the jh/poly-stats branch February 12, 2026 17:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci-barretenberg Run all barretenberg/cpp checks.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants