fix: allocate non-gate selectors at trace-active size instead of dyadic size#20600
Merged
johnathan79717 merged 3 commits intomerge-train/barretenbergfrom Feb 18, 2026
Merged
Conversation
…ic size Non-gate selectors (q_m, q_c, q_l, q_r, q_o, q_4) were allocated at full dyadic_size() even though they are only written within the active trace range. This caused circuits just above a power-of-two boundary to use ~2x memory for selectors compared to circuits just below. Changed allocation from Polynomial(dyadic_size()) to Polynomial(trace_active_range_size(), dyadic_size()), which backs only the active region while still presenting the full virtual size (with virtual zeroes beyond the active range). Also changed get_polynomial_size() to return virtual_size() instead of size(), since the logical polynomial size is the dyadic circuit size, not the backing memory size. Benchmarked on circuits ~2000 gates apart straddling the 2^20 boundary: - Peak RSS for 2^21 dyadic: 2854 MiB -> 2375 MiB (-479 MiB, -17%) - Memory gap between 2^20 and 2^21: 603 MiB -> 126 MiB (-79%) Resolves AztecProtocol/barretenberg#1625.
When non-gate selectors are allocated with smaller backing (trace_active_range_size instead of dyadic_size), the first polynomial in batch_polynomials may be too small to accumulate others via add_scaled. Create a properly sized result polynomial when needed.
Contributor
|
@johnathan79717 I'm not sure how readily we can do this but it should also be possible to download only the SRS content that we need. Worth investigating |
Contributor
Author
|
@ledwards2225 Good idea — the CRS is currently loaded at full |
ledwards2225
approved these changes
Feb 17, 2026
Contributor
ledwards2225
left a comment
There was a problem hiding this comment.
LGTM - One conservative suggestion for a bit of extra safety
Extend the existing max_end check to also track min_start across all polynomials. If the 0th polynomial has a greater start_index than another polynomial in the batch, we now create a result polynomial covering the full [min_start, max_end) range, preventing add_scaled assertion failures.
github-merge-queue bot
pushed a commit
that referenced
this pull request
Feb 18, 2026
BEGIN_COMMIT_OVERRIDE chore: chonk rec ver 0 (#20506) fix: allocate non-gate selectors at trace-active size instead of dyadic size (#20600) chore: numeric audit 0 (#20491) chore: prepare barretenberg-rs for crates.io publishing (#20496) chore: add build_bench to ci-barretenberg-full (#20650) chore: add component graphs for app-proving benchmarks (#20649) END_COMMIT_OVERRIDE
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
q_m,q_c,q_l,q_r,q_o,q_4) attrace_active_range_size()instead ofdyadic_size(), using virtual zeroes for the restget_polynomial_size()to returnvirtual_size()instead ofsize(), since the logical polynomial size is the dyadic circuit sizebatch_polynomialsin Hypernova to handle polynomials with different backing sizes (non-gate selectors now have smaller backing than other entities like table polynomials)Benchmark results
Circuits ~2000 gates apart straddling the 2^20 boundary:
Test plan
ultra_honk_tests— 260 passed, 5 skippedchonk_tests— 20 passedcircuit_checker_tests— 80 passedhypernova_tests— 9 passedResolves AztecProtocol/barretenberg#1625.