feat(brillig): Hoist shared constants across functions to the global space#7216
feat(brillig): Hoist shared constants across functions to the global space#7216
Conversation
…brillig space. Done on the Brillig side
Changes to Brillig bytecode sizes
🧾 Summary (10% most significant diffs)
Full diff report 👇
|
Changes to number of Brillig opcodes executed
🧾 Summary (10% most significant diffs)
Full diff report 👇
|
There was a problem hiding this comment.
⚠️ Performance Alert ⚠️
Possible performance regression was detected for benchmark 'Test Suite Duration'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.20.
| Benchmark suite | Current: 871811d | Previous: a9e9850 | Ratio |
|---|---|---|---|
noir-lang_schnorr_ |
1 s |
0 s |
+∞ |
noir-lang_noir_sort_ |
1 s |
0 s |
+∞ |
AztecProtocol_aztec-packages_noir-projects_noir-protocol-circuits_crates_blob |
64 s |
51 s |
1.25 |
This comment was automatically generated by workflow using github-action-benchmark.
CC: @TomAFrench
There was a problem hiding this comment.
⚠️ Performance Alert ⚠️
Possible performance regression was detected for benchmark 'Compilation Time'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.20.
| Benchmark suite | Current: 40c3b5b | Previous: 49d1b13 | Ratio |
|---|---|---|---|
sha256_regression |
1.23 s |
0.977 s |
1.26 |
regression_4709 |
1.04 s |
0.845 s |
1.23 |
global_var_regression_entry_points |
0.74 s |
0.566 s |
1.31 |
This comment was automatically generated by workflow using github-action-benchmark.
CC: @TomAFrench
compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_block.rs
Outdated
Show resolved
Hide resolved
compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_block.rs
Outdated
Show resolved
Hide resolved
compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_block_variables.rs
Outdated
Show resolved
Hide resolved
compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_globals.rs
Outdated
Show resolved
Hide resolved
compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_globals.rs
Outdated
Show resolved
Hide resolved
test_programs/execution_success/global_var_regression_simple/src/main.nr
Show resolved
Hide resolved
compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_globals.rs
Outdated
Show resolved
Hide resolved
compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_globals.rs
Outdated
Show resolved
Hide resolved
|
Can you explain a bit more on why we don't place these hoisted constants into the main globals map? We should be able to treat them in exactly the same way. |
I decided to do it during Brillig for a few reasons aside this being a Brillig unique operation.
Due to the above reasons, I felt we could do this as part of Brillig gen rather than having to alter the pre-existing SSA. I had considered placing them in the main globals map as well, but ultimately decided to trade-off a new "type" of global and a little extra complexity in Brillig to avoid extra complexity in the SSA passes (most likely it would be constant folding that would be updated) for this Brillig unique feature. |
TomAFrench
left a comment
There was a problem hiding this comment.
blocking this waiting for #7277
|
Just needs conflicts to be addressed now. |
compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_block.rs
Outdated
Show resolved
Hide resolved
compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_block.rs
Outdated
Show resolved
Hide resolved
Co-authored-by: Tom French <15848336+TomAFrench@users.noreply.github.com>
compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_block.rs
Outdated
Show resolved
Hide resolved
Co-authored-by: Tom French <15848336+TomAFrench@users.noreply.github.com>
… into mv/hoist-shared-consts-globally
* master: fix(performance): Remove redundant slice access check from brillig (#7434) chore(docs): updating tutorials and other nits to beta.2 (#7405) feat: LSP hover for integer literals (#7368) feat(experimental): Compile match expressions (#7312) feat(acir_field): Add little-endian byte serialization for FieldElement (#7258) feat: allow unquoting TraitConstraint in trait impl position (#7395) feat(brillig): Hoist shared constants across functions to the global space (#7216) feat(LSP): auto-import via visible reexport (#7409) fix(brillig): Brillig entry point analysis and function specialization through duplication (#7277) chore: redo typo PR by maximevtush (#7425) fix(ssa): Accurately mark binary ops for hoisting and check Div/Mod against induction variable lower bound (#7396) feat!: remove bigint from stdlib (#7411)
…m brillig (noir-lang/noir#7434) chore(docs): updating tutorials and other nits to beta.2 (noir-lang/noir#7405) feat: LSP hover for integer literals (noir-lang/noir#7368) feat(experimental): Compile match expressions (noir-lang/noir#7312) feat(acir_field): Add little-endian byte serialization for FieldElement (noir-lang/noir#7258) feat: allow unquoting TraitConstraint in trait impl position (noir-lang/noir#7395) feat(brillig): Hoist shared constants across functions to the global space (noir-lang/noir#7216) feat(LSP): auto-import via visible reexport (noir-lang/noir#7409) fix(brillig): Brillig entry point analysis and function specialization through duplication (noir-lang/noir#7277) chore: redo typo PR by maximevtush (noir-lang/noir#7425) fix(ssa): Accurately mark binary ops for hoisting and check Div/Mod against induction variable lower bound (noir-lang/noir#7396) feat!: remove bigint from stdlib (noir-lang/noir#7411) chore: bump aztec-packages commit (noir-lang/noir#7415) chore: deprecate `merkle` module of stdlib (noir-lang/noir#7413) chore(ci): lock aztec-packages commit in CI (noir-lang/noir#7414) feat: while statement (noir-lang/noir#7280)
…oir-lang/noir#7434) chore(docs): updating tutorials and other nits to beta.2 (noir-lang/noir#7405) feat: LSP hover for integer literals (noir-lang/noir#7368) feat(experimental): Compile match expressions (noir-lang/noir#7312) feat(acir_field): Add little-endian byte serialization for FieldElement (noir-lang/noir#7258) feat: allow unquoting TraitConstraint in trait impl position (noir-lang/noir#7395) feat(brillig): Hoist shared constants across functions to the global space (noir-lang/noir#7216) feat(LSP): auto-import via visible reexport (noir-lang/noir#7409) fix(brillig): Brillig entry point analysis and function specialization through duplication (noir-lang/noir#7277) chore: redo typo PR by maximevtush (noir-lang/noir#7425) fix(ssa): Accurately mark binary ops for hoisting and check Div/Mod against induction variable lower bound (noir-lang/noir#7396) feat!: remove bigint from stdlib (noir-lang/noir#7411) chore: bump aztec-packages commit (noir-lang/noir#7415) chore: deprecate `merkle` module of stdlib (noir-lang/noir#7413) chore(ci): lock aztec-packages commit in CI (noir-lang/noir#7414) feat: while statement (noir-lang/noir#7280)
Automated pull of development from the [noir](https://github.com/noir-lang/noir) programming language, a dependency of Aztec. BEGIN_COMMIT_OVERRIDE fix(performance): Remove redundant slice access check from brillig (noir-lang/noir#7434) chore(docs): updating tutorials and other nits to beta.2 (noir-lang/noir#7405) feat: LSP hover for integer literals (noir-lang/noir#7368) feat(experimental): Compile match expressions (noir-lang/noir#7312) feat(acir_field): Add little-endian byte serialization for FieldElement (noir-lang/noir#7258) feat: allow unquoting TraitConstraint in trait impl position (noir-lang/noir#7395) feat(brillig): Hoist shared constants across functions to the global space (noir-lang/noir#7216) feat(LSP): auto-import via visible reexport (noir-lang/noir#7409) fix(brillig): Brillig entry point analysis and function specialization through duplication (noir-lang/noir#7277) chore: redo typo PR by maximevtush (noir-lang/noir#7425) fix(ssa): Accurately mark binary ops for hoisting and check Div/Mod against induction variable lower bound (noir-lang/noir#7396) feat!: remove bigint from stdlib (noir-lang/noir#7411) chore: bump aztec-packages commit (noir-lang/noir#7415) chore: deprecate `merkle` module of stdlib (noir-lang/noir#7413) chore(ci): lock aztec-packages commit in CI (noir-lang/noir#7414) feat: while statement (noir-lang/noir#7280) END_COMMIT_OVERRIDE --------- Co-authored-by: Tom French <tom@tomfren.ch>
Description
Problem*
Resolves #7109
Summary*
Before compiling Brillig globals we run an analysis to see which constants are shared across multiple functions. Those values are allocated along with the user-defined globals and then special cased when compiling regular functions. Any repeat constants across functions should be a part of the global read-only memory space and will live throughout the program.
BrilligGlobalscontext structure we now maintain a new map:ConstantAllocationto determine which constant appears in both functions. This was technically recomputed as we calculate aConstantAllocationwhen creating aFunctionContext. For now, I decided to recompute it as it has a minor affect on compilation, but just noting this is a place of optimization in the future.dfg.is_global.Additional Context
Documentation*
Check one:
PR Checklist*
cargo fmton default settings.