Skip to content

chore: refactor codegen_memory#10323

Merged
guipublic merged 7 commits intomasterfrom
gd/codegen_memory
Nov 7, 2025
Merged

chore: refactor codegen_memory#10323
guipublic merged 7 commits intomasterfrom
gd/codegen_memory

Conversation

@guipublic
Copy link
Contributor

@guipublic guipublic commented Oct 30, 2025

Description

Problem*

Following group 6 audit, I noticed a few improvements for codegen_memory.rs

Summary*

Use custom loop implementation for codegen_mem_copy and codegen_mem_copy_from_the_end, to improve the opcode count.
Refactore codegen_brillig_vector_to_heap_vector() and codegen_initialize_externally_returned_vector() to reuse existing functions.

Additional Context

The benchmark results on the mem_copy changes did not show any improvements so I don't think it is worth changing this now. It can be something to look after 1.0, though. I have reverted them.

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.

@guipublic guipublic requested a review from a team October 30, 2025 16:18
@guipublic guipublic added the audit Preparation or execution of security code audits. label Oct 30, 2025
@guipublic guipublic added this to the Group 6 Audited milestone Oct 30, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Oct 30, 2025

Changes to Brillig bytecode sizes

Generated at commit: 0e1caad942d1ee6d90463f4d5ca736e5daff2683, compared to commit: 27c9f674ed4a6f65c7b48f6b73ae37ffbb9969ba

🧾 Summary (10% most significant diffs)

Program Brillig opcodes (+/-) %
regression_10198_inliner_max +2 ❌ +1.24%
regression_10198_inliner_min +2 ❌ +1.24%
regression_10198_inliner_zero +2 ❌ +1.24%
global_slice_rc_regression_8259_inliner_max +2 ❌ +1.05%
global_slice_rc_regression_8259_inliner_min +2 ❌ +1.05%
global_slice_rc_regression_8259_inliner_zero +2 ❌ +1.05%

Full diff report 👇
Program Brillig opcodes (+/-) %
regression_10198_inliner_max 163 (+2) +1.24%
regression_10198_inliner_min 163 (+2) +1.24%
regression_10198_inliner_zero 163 (+2) +1.24%
global_slice_rc_regression_8259_inliner_max 192 (+2) +1.05%
global_slice_rc_regression_8259_inliner_min 192 (+2) +1.05%
global_slice_rc_regression_8259_inliner_zero 192 (+2) +1.05%
regression_9496_inliner_max 545 (+4) +0.74%
regression_9496_inliner_min 545 (+4) +0.74%
regression_9496_inliner_zero 545 (+4) +0.74%
slice_regex_inliner_zero 1,662 (+9) +0.54%
slice_regex_inliner_min 1,800 (+9) +0.50%
slice_regex_inliner_max 2,226 (+9) +0.41%
regression_9271_inliner_max 896 (+3) +0.34%
regression_9271_inliner_min 896 (+3) +0.34%
regression_9271_inliner_zero 896 (+3) +0.34%
slice_coercion_inliner_max 331 (+1) +0.30%
slice_coercion_inliner_min 331 (+1) +0.30%
slice_coercion_inliner_zero 331 (+1) +0.30%
regression_10197_inliner_max 404 (+1) +0.25%
regression_10197_inliner_min 404 (+1) +0.25%
regression_10197_inliner_zero 404 (+1) +0.25%
debug_logs_inliner_max 5,804 (+4) +0.07%
debug_logs_inliner_min 6,005 (+4) +0.07%
debug_logs_inliner_zero 6,005 (+4) +0.07%
regression_9578_inliner_max 6,634 (+2) +0.03%
regression_9578_inliner_zero 6,634 (+2) +0.03%
regression_9578_inliner_min 6,646 (+2) +0.03%

@github-actions
Copy link
Contributor

github-actions bot commented Oct 30, 2025

Changes to number of Brillig opcodes executed

Generated at commit: 0e1caad942d1ee6d90463f4d5ca736e5daff2683, compared to commit: 27c9f674ed4a6f65c7b48f6b73ae37ffbb9969ba

🧾 Summary (10% most significant diffs)

Program Brillig opcodes (+/-) %
regression_10198_inliner_max +2 ❌ +1.27%
regression_10198_inliner_min +2 ❌ +1.27%
regression_10198_inliner_zero +2 ❌ +1.27%
global_slice_rc_regression_8259_inliner_max +2 ❌ +1.05%
global_slice_rc_regression_8259_inliner_min +2 ❌ +1.05%
global_slice_rc_regression_8259_inliner_zero +2 ❌ +1.05%

Full diff report 👇
Program Brillig opcodes (+/-) %
regression_10198_inliner_max 159 (+2) +1.27%
regression_10198_inliner_min 159 (+2) +1.27%
regression_10198_inliner_zero 159 (+2) +1.27%
global_slice_rc_regression_8259_inliner_max 192 (+2) +1.05%
global_slice_rc_regression_8259_inliner_min 192 (+2) +1.05%
global_slice_rc_regression_8259_inliner_zero 192 (+2) +1.05%
regression_9496_inliner_max 519 (+4) +0.78%
regression_9496_inliner_min 519 (+4) +0.78%
regression_9496_inliner_zero 519 (+4) +0.78%
regression_9271_inliner_max 872 (+3) +0.35%
regression_9271_inliner_min 872 (+3) +0.35%
regression_9271_inliner_zero 872 (+3) +0.35%
slice_coercion_inliner_max 328 (+1) +0.31%
slice_coercion_inliner_min 328 (+1) +0.31%
slice_coercion_inliner_zero 328 (+1) +0.31%
slice_regex_inliner_max 3,416 (+9) +0.26%
regression_10197_inliner_max 386 (+1) +0.26%
regression_10197_inliner_min 386 (+1) +0.26%
regression_10197_inliner_zero 386 (+1) +0.26%
slice_regex_inliner_zero 4,037 (+9) +0.22%
slice_regex_inliner_min 4,341 (+9) +0.21%
debug_logs_inliner_max 5,816 (+4) +0.07%
debug_logs_inliner_min 6,029 (+4) +0.07%
debug_logs_inliner_zero 6,029 (+4) +0.07%
regression_9578_inliner_max 6,643 (+2) +0.03%
regression_9578_inliner_zero 6,643 (+2) +0.03%
regression_9578_inliner_min 6,659 (+2) +0.03%

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 'Execution Time'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.20.

Benchmark suite Current: 0c2ef54 Previous: 8b0f07f Ratio
sha512-100-bytes 0.074 s 0.045 s 1.64

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

CC: @TomAFrench

@vezenovm vezenovm added the bench-show Display benchmark results on PR label Oct 30, 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: 73fdae3 Previous: 27c9f67 Ratio
purely_sequential_opcodes 264986 ns/iter (± 1055) 264890 ns/iter (± 894) 1.00
perfectly_parallel_opcodes 233108 ns/iter (± 3411) 239785 ns/iter (± 2976) 0.97
perfectly_parallel_batch_inversion_opcodes 2794161 ns/iter (± 1659) 2801188 ns/iter (± 5326) 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.

Compilation Time

Details
Benchmark suite Current: 73fdae3 Previous: 27c9f67 Ratio
private-kernel-inner 2.04 s 1.994 s 1.02
private-kernel-reset 8.058 s 8.59 s 0.94
private-kernel-tail 1.574 s 1.514 s 1.04
rollup-block-root-first-empty-tx 1.404 s 1.424 s 0.99
rollup-block-root-single-tx 1.42 s 1.39 s 1.02
rollup-block-root 1.46 s 1.46 s 1
rollup-checkpoint-merge 1.466 s 1.48 s 0.99
rollup-checkpoint-root-single-block 428 s 412 s 1.04
rollup-checkpoint-root 422 s 434 s 0.97
rollup-root 1.542 s 1.48 s 1.04
rollup-tx-base-private 21.42 s 21.02 s 1.02
rollup-tx-base-public 82.48 s 84.1 s 0.98
rollup-tx-merge 1.446 s 1.404 s 1.03
semaphore-depth-10 0.797 s 0.806 s 0.99
sha512-100-bytes 1.806 s 1.663 s 1.09

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: 73fdae3 Previous: 27c9f67 Ratio
private-kernel-inner 0.014 s 0.013 s 1.08
private-kernel-reset 0.205 s 0.208 s 0.99
private-kernel-tail 0.012 s 0.012 s 1
rollup-block-root-first-empty-tx 0.003 s 0.003 s 1
rollup-block-root-single-tx 0.002 s 0.003 s 0.67
rollup-block-root 0.004 s 0.004 s 1
rollup-checkpoint-merge 0.003 s 0.003 s 1
rollup-checkpoint-root-single-block 23.9 s 23.6 s 1.01
rollup-checkpoint-root 23.9 s 24.3 s 0.98
rollup-root 0.004 s 0.004 s 1
rollup-tx-base-private 0.341 s 0.339 s 1.01
rollup-tx-base-public 0.257 s 0.258 s 1.00
rollup-tx-merge 0.002 s 0.002 s 1
semaphore-depth-10 0.009 s 0.009 s 1
sha512-100-bytes 0.051 s 0.067 s 0.76

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: 73fdae3 Previous: 27c9f67 Ratio
private-kernel-inner 770.2 KB 770.2 KB 1
private-kernel-reset 2048.4 KB 2048.4 KB 1
private-kernel-tail 627.3 KB 627.3 KB 1
rollup-block-root-first-empty-tx 199.8 KB 199.8 KB 1
rollup-block-root-single-tx 200.2 KB 200.2 KB 1
rollup-block-root 280.4 KB 280.4 KB 1
rollup-checkpoint-merge 363.1 KB 363.1 KB 1
rollup-checkpoint-root-single-block 51639.1 KB 51639.1 KB 1
rollup-checkpoint-root 51678.4 KB 51678.4 KB 1
rollup-root 395.2 KB 395.2 KB 1
rollup-tx-base-private 5620.7 KB 5620.7 KB 1
rollup-tx-base-public 4878.7 KB 4878.7 KB 1
rollup-tx-merge 178.9 KB 178.9 KB 1
semaphore-depth-10 570.9 KB 570.9 KB 1
sha512-100-bytes 506.3 KB 506.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.

Opcode count

Details
Benchmark suite Current: 73fdae3 Previous: 27c9f67 Ratio
private-kernel-inner 18027 opcodes 18027 opcodes 1
private-kernel-reset 80804 opcodes 80804 opcodes 1
private-kernel-tail 17176 opcodes 17176 opcodes 1
rollup-block-root-first-empty-tx 1100 opcodes 1100 opcodes 1
rollup-block-root-single-tx 876 opcodes 876 opcodes 1
rollup-block-root 2253 opcodes 2253 opcodes 1
rollup-checkpoint-merge 2133 opcodes 2133 opcodes 1
rollup-checkpoint-root-single-block 1919761 opcodes 1919761 opcodes 1
rollup-checkpoint-root 1921135 opcodes 1921135 opcodes 1
rollup-root 2608 opcodes 2608 opcodes 1
rollup-tx-base-private 306830 opcodes 306830 opcodes 1
rollup-tx-base-public 262441 opcodes 262441 opcodes 1
rollup-tx-merge 1486 opcodes 1486 opcodes 1
semaphore-depth-10 5699 opcodes 5699 opcodes 1
sha512-100-bytes 13173 opcodes 13173 opcodes 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: 73fdae3 Previous: 27c9f67 Ratio
test_report_AztecProtocol_aztec-packages_noir-projects_aztec-nr 122 s 130 s 0.94
test_report_AztecProtocol_aztec-packages_noir-projects_noir-contracts 132 s 132 s 1
test_report_AztecProtocol_aztec-packages_noir-projects_noir-protocol-circuits_crates_blob 434 s 413 s 1.05
test_report_AztecProtocol_aztec-packages_noir-projects_noir-protocol-circuits_crates_private-kernel-lib 245 s 236 s 1.04
test_report_AztecProtocol_aztec-packages_noir-projects_noir-protocol-circuits_crates_types 142 s 144 s 0.99
test_report_noir-lang_noir-bignum_ 166 s 151 s 1.10
test_report_noir-lang_noir_bigcurve_ 357 s 330 s 1.08
test_report_noir-lang_sha256_ 15 s 16 s 0.94
test_report_noir-lang_sha512_ 15 s 13 s 1.15
test_report_zkpassport_noir-ecdsa_ 1 s 1 s 1
test_report_zkpassport_noir_rsa_ 1 s 1 s 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.

⚠️ 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: 8769d84 Previous: 1324e73 Ratio
test_report_noir-lang_sha512_ 15 s 12 s 1.25

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

CC: @TomAFrench

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: 73fdae3 Previous: 27c9f67 Ratio
private-kernel-inner 270.2 MB 270.2 MB 1
private-kernel-reset 498.29 MB 498.29 MB 1
private-kernel-tail 256.77 MB 256.77 MB 1
rollup-block-root-first-empty-tx 339.76 MB 339.76 MB 1
rollup-block-root-single-tx 338.21 MB 338.2 MB 1.00
rollup-block-root 340.99 MB 340.99 MB 1
rollup-checkpoint-merge 340.96 MB 340.96 MB 1
rollup-checkpoint-root-single-block 11250 MB 11250 MB 1
rollup-checkpoint-root 11260 MB 11260 MB 1
rollup-root 342.5 MB 342.5 MB 1
rollup-tx-base-private 1070 MB 1070 MB 1
rollup-tx-base-public 3030 MB 3030 MB 1
rollup-tx-merge 337.78 MB 337.78 MB 1
semaphore_depth_10 92.17 MB 92.17 MB 1
sha512_100_bytes 185.5 MB 185.47 MB 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.

Execution Memory

Details
Benchmark suite Current: 73fdae3 Previous: 27c9f67 Ratio
private-kernel-inner 260.41 MB 260.41 MB 1
private-kernel-reset 292.14 MB 292.14 MB 1
private-kernel-tail 250.83 MB 250.83 MB 1
rollup-block-root 339.1 MB 339.1 MB 1
rollup-checkpoint-merge 337.86 MB 337.86 MB 1
rollup-checkpoint-root-single-block 1760 MB 1760 MB 1
rollup-checkpoint-root 1760 MB 1760 MB 1
rollup-root 339.09 MB 339.09 MB 1
rollup-tx-base-private 526.54 MB 526.54 MB 1
rollup-tx-base-public 472.94 MB 472.94 MB 1
rollup-tx-merge 337.32 MB 337.32 MB 1
semaphore_depth_10 73.69 MB 73.69 MB 1
sha512_100_bytes 71.95 MB 71.95 MB 1

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

Copy link
Contributor

@aakoshh aakoshh left a comment

Choose a reason for hiding this comment

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

LGTM!

@guipublic guipublic added this pull request to the merge queue Nov 7, 2025
Merged via the queue into master with commit e137fdc Nov 7, 2025
131 checks passed
@guipublic guipublic deleted the gd/codegen_memory branch November 7, 2025 09:45
AztecBot added a commit to AztecProtocol/aztec-packages that referenced this pull request Nov 10, 2025
Automated pull of nightly from the [noir](https://github.com/noir-lang/noir) programming language, a dependency of Aztec.
BEGIN_COMMIT_OVERRIDE
chore(elaborator): Infer type of lambdas in tuple args; more docs (noir-lang/noir#10405)
fix: revert "feat(ACIR): reuse element_type_sizes blocks with the same str… (noir-lang/noir#10428)
chore(frontend): Avoid silent fallback when returning turbofish generics for primitive types (noir-lang/noir#10416)
fix: mark ECDSA verification as `PureWithPredicate` (noir-lang/noir#10423)
fix(parser): don't crash on incomplete type alias (noir-lang/noir#10421)
chore(github): Refine pull request template wording (noir-lang/noir#10418)
chore: refactor codegen_memory (noir-lang/noir#10323)
chore(frontend): Primitive types generic count unit tests (noir-lang/noir#10412)
chore: use SignedField::from_signed in enums.rs (noir-lang/noir#10408)
chore: use `map_data_bus_in_place` in mem2reg (noir-lang/noir#10407)
chore: apply typo fixes from Cantina (noir-lang/noir#10406)
chore(frontend): Various comptime blocks unit tests (noir-lang/noir#10398)
fix: clarify predicate comment in BrilligCall and Call opcodes (noir-lang/noir#10356)
END_COMMIT_OVERRIDE
github-merge-queue bot pushed a commit to AztecProtocol/aztec-packages that referenced this pull request Nov 10, 2025
Automated pull of nightly from the
[noir](https://github.com/noir-lang/noir) programming language, a
dependency of Aztec.
BEGIN_COMMIT_OVERRIDE
chore(elaborator): Infer type of lambdas in tuple args; more docs
(noir-lang/noir#10405)
fix: revert "feat(ACIR): reuse element_type_sizes blocks with the same
str… (noir-lang/noir#10428)
chore(frontend): Avoid silent fallback when returning turbofish generics
for primitive types (noir-lang/noir#10416)
fix: mark ECDSA verification as `PureWithPredicate`
(noir-lang/noir#10423)
fix(parser): don't crash on incomplete type alias
(noir-lang/noir#10421)
chore(github): Refine pull request template wording
(noir-lang/noir#10418)
chore: refactor codegen_memory
(noir-lang/noir#10323)
chore(frontend): Primitive types generic count unit tests
(noir-lang/noir#10412)
chore: use SignedField::from_signed in enums.rs
(noir-lang/noir#10408)
chore: use `map_data_bus_in_place` in mem2reg
(noir-lang/noir#10407)
chore: apply typo fixes from Cantina
(noir-lang/noir#10406)
chore(frontend): Various comptime blocks unit tests
(noir-lang/noir#10398)
fix: clarify predicate comment in BrilligCall and Call opcodes
(noir-lang/noir#10356)
END_COMMIT_OVERRIDE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

audit Preparation or execution of security code audits. bench-show Display benchmark results on PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants