Skip to content

fix(ssa): Remove the array cache from the function inserter#8607

Merged
TomAFrench merged 8 commits intomasterfrom
mv/remove-inserter-array-cache
May 27, 2025
Merged

fix(ssa): Remove the array cache from the function inserter#8607
TomAFrench merged 8 commits intomasterfrom
mv/remove-inserter-array-cache

Conversation

@vezenovm
Copy link
Contributor

@vezenovm vezenovm commented May 21, 2025

Description

Problem*

Resolves #8333

Take this reduction of the original program:

fn main() -> pub [[u8; 32]; 2] {
    let mut result = [[0; 32]; 2];
    let actions_data: [Field; 30] = [0; 30];
    for i in 0..1 {
        result = [actions_data[i].to_be_bytes::<32>(), actions_data[i + 1].to_be_bytes::<32>()];
    }
    result
}

As part of #6071 an array cache was added to the function inserter which is used during unrolling to prevent OOM panics. This array cache also hoists make array instructions out of the loop

In the above program we have a call whose result is used in a make array. That make array containing the call result is then hoisted out of the loop, but the call itself is not hoisted. This leads to a mismatch in the ordering of instructions, thus triggering a panic during inlining. The same panic can be triggerd by normalizing IDs after the unrolling pass (e.g. --show-ssa).

Summary*

#6071 was built before LICM and Brillig globals existed at all (we used to inline arrays wherever the global was used). The cache was a workaround to avoid compilation time/memory blow-ups for large constant arrays used in a loop. I chose to lean into LICM and remove the cache entirely. This allows us to simplify the function inserter and have better separation of concerns (hoisting vs. unrolling).

Additional Context

After this PR it may be worth considering to require LICM to precede unrolling. We currently always run LICM before unrolling, however, we may want to make this requirement more explicit.

Documentation*

Check one:

  • No documentation needed.
  • Documentation included in this PR.
  • [For Experimental Features] Documentation to be submitted in a separate PR.

PR Checklist*

  • I have tested the changes locally.
  • I have formatted the changes with Prettier and/or cargo fmt on default settings.

@vezenovm vezenovm added the bench-show Display benchmark results on PR label May 21, 2025
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

ACVM Benchmarks

Details
Benchmark suite Current: 9f6c366 Previous: a16e848 Ratio
purely_sequential_opcodes 253390 ns/iter (± 447) 261238 ns/iter (± 2167) 0.97
perfectly_parallel_opcodes 223239 ns/iter (± 7007) 232794 ns/iter (± 3185) 0.96
perfectly_parallel_batch_inversion_opcodes 3564917 ns/iter (± 7004) 3574022 ns/iter (± 18752) 1.00

This comment was automatically generated by workflow using github-action-benchmark.

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Artifact Size

Details
Benchmark suite Current: 9f6c366 Previous: a16e848 Ratio
private-kernel-inner 1132.6 KB 1132.6 KB 1
private-kernel-reset 2051 KB 2051 KB 1
private-kernel-tail 586.4 KB 586.4 KB 1
rollup-base-private 5129.1 KB 5129.1 KB 1
rollup-base-public 4070.5 KB 4070.5 KB 1
rollup-block-root-empty 256.7 KB 256.7 KB 1
rollup-block-root-single-tx 25697.8 KB 25697.8 KB 1
rollup-block-root 25721.5 KB 25721.5 KB 1
rollup-merge 181.6 KB 181.6 KB 1
rollup-root 416.5 KB 416.5 KB 1
semaphore-depth-10 636.3 KB 636.3 KB 1

This comment was automatically generated by workflow using github-action-benchmark.

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Compilation Time

Details
Benchmark suite Current: 9f6c366 Previous: a16e848 Ratio
private-kernel-inner 2.324 s 2.308 s 1.01
private-kernel-reset 6.952 s 6.428 s 1.08
private-kernel-tail 1.062 s 1.074 s 0.99
rollup-base-private 17.54 s 16.44 s 1.07
rollup-base-public 15.28 s 13.68 s 1.12
rollup-block-root-empty 1.416 s 1.524 s 0.93
rollup-block-root-single-tx 130 s 129 s 1.01
rollup-block-root 128 s 122 s 1.05
rollup-merge 1.194 s 1.192 s 1.00
rollup-root 1.694 s 1.668 s 1.02
semaphore-depth-10 0.834 s 0.91 s 0.92

This comment was automatically generated by workflow using github-action-benchmark.

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Execution Time

Details
Benchmark suite Current: 9f6c366 Previous: a16e848 Ratio
private-kernel-inner 0.028 s 0.028 s 1
private-kernel-reset 0.163 s 0.161 s 1.01
private-kernel-tail 0.011 s 0.011 s 1
rollup-base-private 0.316 s 0.312 s 1.01
rollup-base-public 0.202 s 0.194 s 1.04
rollup-block-root 11.7 s 11.5 s 1.02
rollup-merge 0.004 s 0.004 s 1
rollup-root 0.009 s 0.009 s 1
semaphore-depth-10 0.021 s 0.02 s 1.05

This comment was automatically generated by workflow using github-action-benchmark.

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Execution Memory

Details
Benchmark suite Current: 9f6c366 Previous: a16e848 Ratio
private-kernel-inner 242.04 MB 242.04 MB 1
private-kernel-reset 264.09 MB 264.09 MB 1
private-kernel-tail 217.23 MB 217.23 MB 1
rollup-base-private 577.89 MB 577.89 MB 1
rollup-base-public 574.21 MB 574.21 MB 1
rollup-block-root 1460 MB 1460 MB 1
rollup-merge 399.73 MB 399.73 MB 1
rollup-root 405.29 MB 405.29 MB 1
semaphore_depth_10 92.93 MB 92.93 MB 1

This comment was automatically generated by workflow using github-action-benchmark.

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Compilation Memory

Details
Benchmark suite Current: 9f6c366 Previous: a16e848 Ratio
private-kernel-inner 333.06 MB 333.11 MB 1.00
private-kernel-reset 572.37 MB 572.37 MB 1
private-kernel-tail 232.88 MB 232.89 MB 1.00
rollup-base-private 1470 MB 1470 MB 1
rollup-base-public 1630 MB 1630 MB 1
rollup-block-root-empty 429.54 MB 429.52 MB 1.00
rollup-block-root-single-tx 7240 MB 7240 MB 1
rollup-block-root 7250 MB 7250 MB 1
rollup-merge 413.83 MB 413.81 MB 1.00
rollup-root 468.04 MB 468.07 MB 1.00
semaphore_depth_10 128.37 MB 128.37 MB 1

This comment was automatically generated by workflow using github-action-benchmark.

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Test Suite Duration

Details
Benchmark suite Current: 9f6c366 Previous: a16e848 Ratio
test_report_AztecProtocol_aztec-packages_noir-projects_aztec-nr 66 s 65 s 1.02
test_report_AztecProtocol_aztec-packages_noir-projects_noir-contracts 96 s 98 s 0.98
test_report_AztecProtocol_aztec-packages_noir-projects_noir-protocol-circuits_crates_blob 40 s 43 s 0.93
test_report_AztecProtocol_aztec-packages_noir-projects_noir-protocol-circuits_crates_private-kernel-lib 197 s 185 s 1.06
test_report_AztecProtocol_aztec-packages_noir-projects_noir-protocol-circuits_crates_rollup-lib 188 s 181 s 1.04
test_report_AztecProtocol_aztec-packages_noir-projects_noir-protocol-circuits_crates_types 62 s 60 s 1.03
test_report_noir-lang_noir-bignum_ 382 s 379 s 1.01
test_report_noir-lang_noir_bigcurve_ 234 s 264 s 0.89
test_report_noir-lang_sha512_ 32 s 31 s 1.03
test_report_zkpassport_noir_rsa_ 4 s 2 s 2

This comment was automatically generated by workflow using github-action-benchmark.

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

⚠️ 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: 9f6c366 Previous: a16e848 Ratio
test_report_zkpassport_noir_rsa_ 4 s 2 s 2

This comment was automatically generated by workflow using github-action-benchmark.

CC: @TomAFrench

@vezenovm
Copy link
Contributor Author

Huh looks like all the reports aside semaphore are gone.

@TomAFrench
Copy link
Member

Yeah, they got broken by a previous PR. 🤷

@vezenovm
Copy link
Contributor Author

Yeah, they got broken by a previous PR. 🤷

Assumed as such, I just didn't have the chance to investigate yet.

@TomAFrench
Copy link
Member

It needs a sync to be fixed.

@vezenovm vezenovm requested review from a team and jfecher May 23, 2025 18:52
@TomAFrench TomAFrench enabled auto-merge May 27, 2025 10:00
@TomAFrench TomAFrench added this pull request to the merge queue May 27, 2025
Merged via the queue into master with commit 3da5288 May 27, 2025
118 checks passed
@TomAFrench TomAFrench deleted the mv/remove-inserter-array-cache branch May 27, 2025 11:07
github-merge-queue bot pushed a commit to AztecProtocol/aztec-packages that referenced this pull request Jun 1, 2025
Automated pull of nightly from the
[noir](https://github.com/noir-lang/noir) programming language, a
dependency of Aztec.
BEGIN_COMMIT_OVERRIDE
fix(fmt): correctly format mixed secondary attributes and doc comments
(noir-lang/noir#8735)
fix!: require types for trait impl associated constants
(noir-lang/noir#8734)
fix!: Prevent returning references from if expressions
(noir-lang/noir#8731)
fix: cast signed to u1 follow-up
(noir-lang/noir#8730)
fix: cast signed to u1 (noir-lang/noir#8720)
fix: do not mutate arrays later copied inside other arrays
(noir-lang/noir#8701)
chore: box `AsTraitPath` and `TypePath` in `ExpressionKind`
(noir-lang/noir#8716)
fix: general solution for accessing associated constants
(noir-lang/noir#8417)
fix(ssa): Validate checked signed add/sub is followed by a truncate
(noir-lang/noir#8706)
chore: add pre- and post-check on `array_set` optimization pass
(noir-lang/noir#8714)
fix: merge expr bindings with instantiations bindings during
monomorphization (noir-lang/noir#8713)
fix: better way to do LSP file overrides
(noir-lang/noir#8702)
fix(fmt): correct indentation when formatting long struct patterns
(noir-lang/noir#8711)
fix(fuzz): Prevent breaking/continuing out from let blocks in the AST
fuzzer (noir-lang/noir#8708)
chore: remove override for zero length inputs
(noir-lang/noir#8709)
feat: Replace converging jmpif with empty block destinations with a
single jmp (noir-lang/noir#8613)
feat(cli): Add `nargo interpret` command
(noir-lang/noir#8700)
chore: more 1-tuple printing fixes
(noir-lang/noir#8699)
chore(fuzz): Fuzz the SSA parser
(noir-lang/noir#8647)
fix: (SSA parser) translate blocks in logical order rather than syntax
order (noir-lang/noir#8668)
fix(SSA): show and parse range_check's assert_message
(noir-lang/noir#8652)
chore: Show the step number in the SSA message
(noir-lang/noir#8698)
chore(docs): Add pointers to tests
(noir-lang/noir#8695)
chore(fuzz): Capture comptime print output
(noir-lang/noir#8635)
fix: nargo expand reexports correctly implemented
(noir-lang/noir#8693)
feat(cli): Show multiple SSA passes
(noir-lang/noir#8692)
chore(test): Add regression test for defunctionalize
(noir-lang/noir#8691)
chore: add an assertion when parsing SSA that all functions are
well-formed (noir-lang/noir#8671)
feat!: prevent compiling blake3 hashes which barretenberg cannot prove
(noir-lang/noir#8690)
fix(ssa): Remove the array cache from the function inserter
(noir-lang/noir#8607)
chore: bump external pinned commits
(noir-lang/noir#8684)
chore: reenable fuzzing tests in CI
(noir-lang/noir#8688)
fix: Handle `&mut function` in defunctionalize
(noir-lang/noir#8665)
fix(defunctionalize): Higher order functions (HOF) dynamic dispatch and
HOFs in arrays (noir-lang/noir#8672)
chore(ci): avoid running fuzzer tests in the merge queue
(noir-lang/noir#8664)
fix: Make casts in `comptime` consistent with runtime casts
(noir-lang/noir#8669)
fix: relax connectedness requirement on purity analysis pass
(noir-lang/noir#8667)
fix: always use `u32` for indexing arrays in SSA
(noir-lang/noir#8633)
chore: explicitly pull from `next` branch in aztec-packages
(noir-lang/noir#8660)
chore(fuzz): Build the dictionary from the SSA
(noir-lang/noir#8591)
chore(docs): Remove old versioned docs
(noir-lang/noir#8061)
chore: bump external pinned commits
(noir-lang/noir#8634)
fix(SSA): don't use string literal if byte is "form feed" ('\f')
(noir-lang/noir#8653)
chore(defunctionalize): Add regression test for missing lambda variants
panic (noir-lang/noir#8642)
chore(ci): Do not run ast_fuzzer orig vs. morph in ci
(noir-lang/noir#8646)
fix: disable underflow fix for fields
(noir-lang/noir#8631)
fix: revert "fix: error on unused generic in trait impl
(noir-lang/noir#8395)"
(noir-lang/noir#8636)
fix(ssa interpreter): Default to zero when we have an overflowing shl
(noir-lang/noir#8638)
fix: ensure that purity analysis pass explores all functions
(noir-lang/noir#8452)
feat: acir_formal_proofs (noir-lang/noir#8140)
fix: error on unused generic in trait impl
(noir-lang/noir#8395)
fix(expand): use re-exports for non-visibile items
(noir-lang/noir#8374)
END_COMMIT_OVERRIDE

---------

Co-authored-by: AztecBot <tech@aztecprotocol.com>
Co-authored-by: Tom French <15848336+TomAFrench@users.noreply.github.com>
Co-authored-by: Ary Borenszweig <asterite@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bench-show Display benchmark results on PR

Projects

None yet

2 participants