Skip to content

fix(brillig): Skip decrementing ref-count in array/vector copy and other refactors#10335

Merged
aakoshh merged 31 commits intomasterfrom
af/audit-brillig-gen-5
Nov 11, 2025
Merged

fix(brillig): Skip decrementing ref-count in array/vector copy and other refactors#10335
aakoshh merged 31 commits intomasterfrom
af/audit-brillig-gen-5

Conversation

@aakoshh
Copy link
Contributor

@aakoshh aakoshh commented Oct 31, 2025

Description

Problem*

The last piece of Brillig codegen I haven't audited: procedures.

Summary*

  • Fix the decrement of the ref-count:
  • Update the SSA interpreter to also decrease the refcount of the source array when we make a copy
  • Add docs to procedures
  • Add a make_scratch_registers helper to make it easier to match the allocate_scratch_registers further down.
  • Add a codegen_decrease_rc helper to make sure we write back to the heap.
  • Make codegen_initialize_rc publicly available so setting the RC to 1 is more uniform.
  • Add codegen_usize_equals_one helper to make RC==1 checks a bit easier.
  • Change codegen_read_vector_metadata to return allocated registers, like all the other codegen_read_* methods, and make it more difficult to mix up fields and parameter ordering.
  • Rename all new_vector_ to destination_vector_, so we only have 2 names (destination and target) rather than 3 for the same thing (kept target because it matches the source in the number of letters 🤷 )
  • Add codegen_read_rc and codegen_read_vector_rc to reduce the number of places that know the layout of arrays and vectors by reading their pointers into an RC without going through some method.

Additional Context

The increase in the number of opcodes reference_counts_slices_inliner_0 test is because I added a new unconstrained method to it.

The smaller decreases are because of a reuse of a constant in to_radix for example, rather than declaring it as another constant.

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.

@aakoshh aakoshh changed the title chore(audit): Minor refactorings in chore(audit): Minor refactorings in Brillig procedures Oct 31, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Oct 31, 2025

Changes to Brillig bytecode sizes

Generated at commit: 013f3fe2577bbb6e2e498503e5ddc7694a58bde8, compared to commit: 2a27b186687cab46e6976a68250833d63fd402ec

🧾 Summary (10% most significant diffs)

Program Brillig opcodes (+/-) %
reference_counts_slices_inliner_0_inliner_max +56 ❌ +7.24%
reference_counts_slices_inliner_0_inliner_zero +43 ❌ +4.29%
reference_counts_slices_inliner_0_inliner_min +51 ❌ +4.23%
reference_counts_inliner_min_inliner_max +12 ❌ +1.61%
reference_counts_inliner_0_inliner_max +12 ❌ +1.61%
array_rc_regression_7842_inliner_min -1 ✅ -1.01%
global_array_rc_regression_8259_inliner_max -1 ✅ -1.02%
global_array_rc_regression_8259_inliner_min -1 ✅ -1.02%
mutate_array_copy_inliner_min -1 ✅ -1.02%
global_array_rc_regression_8259_inliner_zero -1 ✅ -1.02%
regression_8975_inliner_min -1 ✅ -1.08%
array_dynamic_main_output_inliner_max -1 ✅ -1.11%
array_dynamic_main_output_inliner_min -1 ✅ -1.11%
array_dynamic_main_output_inliner_zero -1 ✅ -1.11%
simple_radix_inliner_max -1 ✅ -1.35%
simple_radix_inliner_min -1 ✅ -1.35%
simple_radix_inliner_zero -1 ✅ -1.35%
to_le_bytes_inliner_min -2 ✅ -1.47%
to_le_bytes_inliner_max -2 ✅ -1.57%
to_le_bytes_inliner_zero -2 ✅ -1.57%
to_bytes_integration_inliner_max -2 ✅ -2.22%
to_bytes_integration_inliner_min -2 ✅ -2.22%
to_bytes_integration_inliner_zero -2 ✅ -2.22%

Full diff report 👇
Program Brillig opcodes (+/-) %
reference_counts_slices_inliner_0_inliner_max 829 (+56) +7.24%
reference_counts_slices_inliner_0_inliner_zero 1,045 (+43) +4.29%
reference_counts_slices_inliner_0_inliner_min 1,257 (+51) +4.23%
reference_counts_inliner_min_inliner_max 756 (+12) +1.61%
reference_counts_inliner_0_inliner_max 756 (+12) +1.61%
reference_counts_inliner_0_inliner_zero 887 (+6) +0.68%
reference_counts_inliner_min_inliner_zero 887 (+6) +0.68%
reference_counts_inliner_0_inliner_min 1,035 (+6) +0.58%
reference_counts_inliner_min_inliner_min 1,035 (+6) +0.58%
hashmap_inliner_max 18,576 (-1) -0.01%
uhashmap_inliner_max 11,262 (-1) -0.01%
hashmap_inliner_min 8,894 (-1) -0.01%
hashmap_inliner_zero 7,976 (-1) -0.01%
uhashmap_inliner_min 7,185 (-1) -0.01%
uhashmap_inliner_zero 6,921 (-1) -0.01%
poseidon_bn254_hash_width_3_inliner_max 4,831 (-1) -0.02%
regression_5252_inliner_max 4,018 (-1) -0.02%
poseidonsponge_x5_254_inliner_max 3,674 (-1) -0.03%
slices_inliner_min 2,670 (-1) -0.04%
poseidon_bn254_hash_width_3_inliner_min 4,714 (-2) -0.04%
poseidon_bn254_hash_width_3_inliner_zero 4,421 (-2) -0.05%
slices_inliner_max 2,157 (-1) -0.05%
slice_dynamic_index_inliner_min 2,149 (-1) -0.05%
slices_inliner_zero 2,121 (-1) -0.05%
regression_5252_inliner_min 3,349 (-2) -0.06%
slice_dynamic_index_inliner_max 1,625 (-1) -0.06%
slice_dynamic_index_inliner_zero 1,625 (-1) -0.06%
regression_5252_inliner_zero 3,223 (-2) -0.06%
nested_array_dynamic_inliner_max 1,606 (-1) -0.06%
higher_order_functions_inliner_min 1,591 (-1) -0.06%
poseidonsponge_x5_254_inliner_min 3,003 (-2) -0.07%
poseidonsponge_x5_254_inliner_zero 2,882 (-2) -0.07%
nested_array_dynamic_inliner_min 1,332 (-1) -0.08%
nested_array_dynamic_inliner_zero 1,332 (-1) -0.08%
brillig_cow_regression_inliner_max 1,198 (-1) -0.08%
brillig_cow_regression_inliner_zero 1,198 (-1) -0.08%
reference_counts_inliner_max_inliner_min 1,028 (-1) -0.10%
regression_1144_1169_2399_6609_inliner_min 1,000 (-1) -0.10%
regression_1144_1169_2399_6609_inliner_max 897 (-1) -0.11%
regression_1144_1169_2399_6609_inliner_zero 897 (-1) -0.11%
reference_counts_inliner_max_inliner_zero 880 (-1) -0.11%
array_to_slice_inliner_min 847 (-1) -0.12%
higher_order_functions_inliner_zero 720 (-1) -0.14%
array_to_slice_inliner_zero 667 (-1) -0.15%
regression_6674_3_inliner_min 639 (-1) -0.16%
no_predicates_numeric_generic_poseidon_inliner_max 618 (-1) -0.16%
fold_numeric_generic_poseidon_inliner_max 618 (-1) -0.16%
brillig_cow_regression_inliner_min 1,206 (-2) -0.17%
fold_numeric_generic_poseidon_inliner_min 559 (-1) -0.18%
no_predicates_numeric_generic_poseidon_inliner_min 559 (-1) -0.18%
higher_order_functions_inliner_max 540 (-1) -0.18%
fold_complex_outputs_inliner_min 514 (-1) -0.19%
fold_numeric_generic_poseidon_inliner_zero 499 (-1) -0.20%
no_predicates_numeric_generic_poseidon_inliner_zero 499 (-1) -0.20%
conditional_1_inliner_max 496 (-1) -0.20%
array_to_slice_inliner_max 490 (-1) -0.20%
regression_6674_3_inliner_max 481 (-1) -0.21%
regression_6674_3_inliner_zero 481 (-1) -0.21%
fold_2_to_17_inliner_max 469 (-1) -0.21%
numeric_type_alias_inliner_min 464 (-1) -0.22%
array_sort_inliner_min 463 (-1) -0.22%
conditional_1_inliner_min 463 (-1) -0.22%
conditional_1_inliner_zero 463 (-1) -0.22%
fold_complex_outputs_inliner_zero 443 (-1) -0.23%
slice_dynamic_insert_inliner_min 432 (-1) -0.23%
fold_complex_outputs_inliner_max 419 (-1) -0.24%
brillig_pedersen_inliner_max 407 (-1) -0.25%
pedersen_check_inliner_max 407 (-1) -0.25%
brillig_pedersen_inliner_min 407 (-1) -0.25%
pedersen_check_inliner_min 407 (-1) -0.25%
pedersen_check_inliner_zero 407 (-1) -0.25%
brillig_pedersen_inliner_zero 407 (-1) -0.25%
array_sort_inliner_max 406 (-1) -0.25%
array_sort_inliner_zero 406 (-1) -0.25%
aes128_encrypt_inliner_max 397 (-1) -0.25%
regression_struct_array_conditional_inliner_max 394 (-1) -0.25%
regression_struct_array_conditional_inliner_min 394 (-1) -0.25%
regression_struct_array_conditional_inliner_zero 394 (-1) -0.25%
array_dynamic_blackbox_input_inliner_min 385 (-1) -0.26%
aes128_encrypt_inliner_min 382 (-1) -0.26%
slice_dynamic_insert_inliner_max 381 (-1) -0.26%
slice_dynamic_insert_inliner_zero 381 (-1) -0.26%
aes128_encrypt_inliner_zero 373 (-1) -0.27%
regression_9160_inliner_max 365 (-1) -0.27%
regression_9160_inliner_min 365 (-1) -0.27%
regression_9160_inliner_zero 365 (-1) -0.27%
array_dynamic_blackbox_input_inliner_max 364 (-1) -0.27%
array_dynamic_blackbox_input_inliner_zero 364 (-1) -0.27%
simple_shield_inliner_min 694 (-2) -0.29%
simple_shield_inliner_max 677 (-2) -0.29%
simple_shield_inliner_zero 677 (-2) -0.29%
brillig_cow_inliner_max 334 (-1) -0.30%
numeric_type_alias_inliner_max 333 (-1) -0.30%
numeric_type_alias_inliner_zero 333 (-1) -0.30%
array_dynamic_nested_blackbox_input_inliner_min 329 (-1) -0.30%
brillig_cow_inliner_min 328 (-1) -0.30%
fold_2_to_17_inliner_min 327 (-1) -0.30%
array_dynamic_nested_blackbox_input_inliner_max 319 (-1) -0.31%
array_dynamic_nested_blackbox_input_inliner_zero 319 (-1) -0.31%
fold_2_to_17_inliner_zero 315 (-1) -0.32%
array_dynamic_inliner_min 307 (-1) -0.32%
bench_2_to_17_inliner_min 306 (-1) -0.33%
array_dynamic_inliner_max 297 (-1) -0.34%
array_dynamic_inliner_zero 297 (-1) -0.34%
last_uses_regression_8935_inliner_max 295 (-1) -0.34%
last_uses_regression_8935_inliner_min 295 (-1) -0.34%
last_uses_regression_8935_inliner_zero 295 (-1) -0.34%
regression_11294_inliner_min 289 (-1) -0.34%
merkle_insert_inliner_max 553 (-2) -0.36%
encrypted_log_regression_inliner_min 275 (-1) -0.36%
wildcard_type_inliner_min 270 (-1) -0.37%
bench_2_to_17_inliner_max 268 (-1) -0.37%
encrypted_log_regression_inliner_max 262 (-1) -0.38%
encrypted_log_regression_inliner_zero 262 (-1) -0.38%
pedersen_hash_inliner_max 261 (-1) -0.38%
pedersen_hash_inliner_min 261 (-1) -0.38%
pedersen_hash_inliner_zero 261 (-1) -0.38%
wildcard_type_inliner_max 260 (-1) -0.38%
wildcard_type_inliner_zero 260 (-1) -0.38%
regression_6674_2_inliner_min 258 (-1) -0.39%
array_dedup_regression_inliner_max 257 (-1) -0.39%
array_dedup_regression_inliner_min 257 (-1) -0.39%
array_dedup_regression_inliner_zero 257 (-1) -0.39%
a_7_function_inliner_max 513 (-2) -0.39%
bench_2_to_17_inliner_zero 251 (-1) -0.40%
regression_9860_inliner_max 241 (-1) -0.41%
regression_9860_inliner_min 241 (-1) -0.41%
brillig_cow_inliner_zero 241 (-1) -0.41%
regression_9860_inliner_zero 241 (-1) -0.41%
regression_6674_1_inliner_min 236 (-1) -0.42%
regression_11294_inliner_max 224 (-1) -0.44%
regression_11294_inliner_zero 224 (-1) -0.44%
a_7_function_inliner_min 445 (-2) -0.45%
regression_6674_1_inliner_max 222 (-1) -0.45%
regression_6674_2_inliner_max 222 (-1) -0.45%
a_7_function_inliner_zero 435 (-2) -0.46%
regression_9116_inliner_min 216 (-1) -0.46%
regression_9116_inliner_max 206 (-1) -0.48%
regression_9116_inliner_zero 206 (-1) -0.48%
to_be_bytes_inliner_min 195 (-1) -0.51%
merkle_insert_inliner_zero 384 (-2) -0.52%
databus_two_calldata_inliner_max 191 (-1) -0.52%
databus_two_calldata_inliner_min 191 (-1) -0.52%
global_nested_array_regression_9270_inliner_min 191 (-1) -0.52%
databus_two_calldata_inliner_zero 191 (-1) -0.52%
regression_6674_1_inliner_zero 189 (-1) -0.53%
regression_6674_2_inliner_zero 189 (-1) -0.53%
merkle_insert_inliner_min 375 (-2) -0.53%
to_be_bytes_inliner_max 186 (-1) -0.53%
to_be_bytes_inliner_zero 186 (-1) -0.53%
regression_9037_inliner_max 184 (-1) -0.54%
regression_9037_inliner_min 184 (-1) -0.54%
regression_9037_inliner_zero 184 (-1) -0.54%
global_nested_array_regression_9270_inliner_max 183 (-1) -0.54%
global_nested_array_regression_9270_inliner_zero 183 (-1) -0.54%
regression_8174_inliner_max 180 (-1) -0.55%
regression_8174_inliner_min 180 (-1) -0.55%
regression_8174_inliner_zero 180 (-1) -0.55%
reference_only_used_as_alias_inliner_min 176 (-1) -0.56%
pedersen_commitment_inliner_max 162 (-1) -0.61%
pedersen_commitment_inliner_min 162 (-1) -0.61%
pedersen_commitment_inliner_zero 162 (-1) -0.61%
brillig_rc_regression_6123_inliner_min 158 (-1) -0.63%
nested_dyn_array_regression_5782_inliner_max 142 (-1) -0.70%
nested_dyn_array_regression_5782_inliner_min 142 (-1) -0.70%
nested_dyn_array_regression_5782_inliner_zero 142 (-1) -0.70%
regression_9102_inliner_min 138 (-1) -0.72%
regression_9907_inliner_min 132 (-1) -0.75%
regression_9102_inliner_max 130 (-1) -0.76%
regression_9102_inliner_zero 130 (-1) -0.76%
array_if_cond_simple_inliner_max 126 (-1) -0.79%
array_if_cond_simple_inliner_min 126 (-1) -0.79%
array_if_cond_simple_inliner_zero 126 (-1) -0.79%
regression_9329_inliner_min 124 (-1) -0.80%
brillig_cow_assign_inliner_max 123 (-1) -0.81%
brillig_cow_assign_inliner_min 123 (-1) -0.81%
brillig_cow_assign_inliner_zero 123 (-1) -0.81%
regression_9907_inliner_max 121 (-1) -0.82%
regression_9907_inliner_zero 121 (-1) -0.82%
regression_9329_inliner_max 114 (-1) -0.87%
regression_9329_inliner_zero 114 (-1) -0.87%
array_len_inliner_max 112 (-1) -0.88%
array_len_inliner_min 112 (-1) -0.88%
array_len_inliner_zero 112 (-1) -0.88%
fold_call_witness_condition_inliner_max 111 (-1) -0.89%
fold_call_witness_condition_inliner_min 111 (-1) -0.89%
fold_call_witness_condition_inliner_zero 111 (-1) -0.89%
regression_7128_inliner_max 110 (-1) -0.90%
regression_7128_inliner_min 110 (-1) -0.90%
regression_7128_inliner_zero 110 (-1) -0.90%
regression_9725_2_inliner_min 108 (-1) -0.92%
regression_mem_op_predicate_inliner_max 103 (-1) -0.96%
regression_mem_op_predicate_inliner_min 103 (-1) -0.96%
regression_mem_op_predicate_inliner_zero 103 (-1) -0.96%
array_rc_regression_7842_inliner_min 98 (-1) -1.01%
global_array_rc_regression_8259_inliner_max 97 (-1) -1.02%
global_array_rc_regression_8259_inliner_min 97 (-1) -1.02%
mutate_array_copy_inliner_min 97 (-1) -1.02%
global_array_rc_regression_8259_inliner_zero 97 (-1) -1.02%
regression_8975_inliner_min 92 (-1) -1.08%
array_dynamic_main_output_inliner_max 89 (-1) -1.11%
array_dynamic_main_output_inliner_min 89 (-1) -1.11%
array_dynamic_main_output_inliner_zero 89 (-1) -1.11%
simple_radix_inliner_max 73 (-1) -1.35%
simple_radix_inliner_min 73 (-1) -1.35%
simple_radix_inliner_zero 73 (-1) -1.35%
to_le_bytes_inliner_min 134 (-2) -1.47%
to_le_bytes_inliner_max 125 (-2) -1.57%
to_le_bytes_inliner_zero 125 (-2) -1.57%
to_bytes_integration_inliner_max 88 (-2) -2.22%
to_bytes_integration_inliner_min 88 (-2) -2.22%
to_bytes_integration_inliner_zero 88 (-2) -2.22%

@github-actions
Copy link
Contributor

github-actions bot commented Oct 31, 2025

Changes to number of Brillig opcodes executed

Generated at commit: 013f3fe2577bbb6e2e498503e5ddc7694a58bde8, compared to commit: 2a27b186687cab46e6976a68250833d63fd402ec

🧾 Summary (10% most significant diffs)

Program Brillig opcodes (+/-) %
global_nested_array_regression_9270_inliner_min -2 ✅ -0.76%
brillig_rc_regression_6123_inliner_min -2 ✅ -0.77%
global_nested_array_regression_9270_inliner_max -2 ✅ -0.79%
global_nested_array_regression_9270_inliner_zero -2 ✅ -0.79%
regression_9907_inliner_max -1 ✅ -0.80%
regression_9907_inliner_zero -1 ✅ -0.80%
regression_9439_inliner_max -1 ✅ -0.87%
regression_9439_inliner_min -1 ✅ -0.87%
regression_9439_inliner_zero -1 ✅ -0.87%
array_rc_regression_7842_inliner_min -1 ✅ -0.92%
mutate_array_copy_inliner_min -1 ✅ -0.93%
regression_9725_2_inliner_min -1 ✅ -0.96%
simple_radix_inliner_max -1 ✅ -1.47%
simple_radix_inliner_min -1 ✅ -1.47%
simple_radix_inliner_zero -1 ✅ -1.47%

Full diff report 👇
Program Brillig opcodes (+/-) %
brillig_cow_regression_inliner_min 189,047 (-1) -0.00%
poseidonsponge_x5_254_inliner_max 151,499 (-34) -0.02%
regression_5252_inliner_max 752,672 (-176) -0.02%
poseidon_bn254_hash_width_3_inliner_max 136,432 (-34) -0.02%
array_dynamic_blackbox_input_inliner_min 6,488 (-2) -0.03%
array_dynamic_blackbox_input_inliner_max 6,459 (-2) -0.03%
array_dynamic_blackbox_input_inliner_zero 6,459 (-2) -0.03%
a_7_function_inliner_min 2,116 (-1) -0.05%
a_7_function_inliner_zero 2,102 (-1) -0.05%
conditional_1_inliner_min 1,846 (-1) -0.05%
conditional_1_inliner_zero 1,846 (-1) -0.05%
simple_shield_inliner_min 1,829 (-1) -0.05%
conditional_1_inliner_max 1,820 (-1) -0.05%
nested_array_in_slice_inliner_min 1,475 (-1) -0.07%
nested_array_in_slice_inliner_zero 1,475 (-1) -0.07%
nested_array_in_slice_inliner_max 1,382 (-1) -0.07%
poseidonsponge_x5_254_inliner_min 185,001 (-138) -0.07%
regression_5252_inliner_min 923,319 (-692) -0.07%
poseidonsponge_x5_254_inliner_zero 183,096 (-138) -0.08%
regression_5252_inliner_zero 911,439 (-696) -0.08%
poseidon_bn254_hash_width_3_inliner_min 168,232 (-135) -0.08%
fold_numeric_generic_poseidon_inliner_max 3,727 (-3) -0.08%
no_predicates_numeric_generic_poseidon_inliner_max 3,727 (-3) -0.08%
regression_11294_inliner_min 1,238 (-1) -0.08%
merkle_insert_inliner_min 2,448 (-2) -0.08%
poseidon_bn254_hash_width_3_inliner_zero 164,300 (-135) -0.08%
array_dynamic_nested_blackbox_input_inliner_min 1,196 (-1) -0.08%
array_dynamic_nested_blackbox_input_inliner_max 1,182 (-1) -0.08%
array_dynamic_nested_blackbox_input_inliner_zero 1,182 (-1) -0.08%
regression_11294_inliner_max 1,127 (-1) -0.09%
regression_11294_inliner_zero 1,127 (-1) -0.09%
uhashmap_inliner_min 168,569 (-150) -0.09%
uhashmap_inliner_zero 163,670 (-150) -0.09%
a_7_function_inliner_max 2,031 (-2) -0.10%
to_le_bytes_inliner_min 1,000 (-1) -0.10%
to_le_bytes_inliner_max 987 (-1) -0.10%
to_le_bytes_inliner_zero 987 (-1) -0.10%
to_bytes_integration_inliner_max 1,922 (-2) -0.10%
to_bytes_integration_inliner_min 1,922 (-2) -0.10%
to_bytes_integration_inliner_zero 1,922 (-2) -0.10%
hashmap_inliner_min 75,459 (-82) -0.11%
hashmap_inliner_zero 71,273 (-82) -0.11%
uhashmap_inliner_max 143,170 (-166) -0.12%
regression_6674_3_inliner_min 1,488 (-2) -0.13%
nested_array_dynamic_inliner_min 2,727 (-4) -0.15%
nested_array_dynamic_inliner_zero 2,727 (-4) -0.15%
nested_array_dynamic_inliner_max 2,525 (-4) -0.16%
regression_6674_3_inliner_max 1,211 (-2) -0.16%
regression_6674_3_inliner_zero 1,211 (-2) -0.16%
regression_capacity_tracker_inliner_max 567 (-1) -0.18%
regression_capacity_tracker_inliner_min 567 (-1) -0.18%
regression_capacity_tracker_inliner_zero 567 (-1) -0.18%
regression_9496_inliner_max 518 (-1) -0.19%
regression_9496_inliner_min 518 (-1) -0.19%
regression_9496_inliner_zero 518 (-1) -0.19%
slice_dynamic_insert_inliner_max 951 (-2) -0.21%
slice_dynamic_insert_inliner_zero 951 (-2) -0.21%
brillig_cow_inliner_max 926 (-2) -0.22%
slice_dynamic_index_inliner_min 4,557 (-10) -0.22%
hashmap_inliner_max 56,920 (-137) -0.24%
slice_loop_inliner_min 1,159 (-3) -0.26%
slice_loop_inliner_zero 1,145 (-3) -0.26%
array_to_slice_inliner_min 1,858 (-5) -0.27%
brillig_cow_inliner_zero 715 (-2) -0.28%
slice_dynamic_index_inliner_max 3,574 (-10) -0.28%
slice_dynamic_index_inliner_zero 3,574 (-10) -0.28%
array_to_slice_inliner_zero 1,774 (-5) -0.28%
slice_dynamic_insert_inliner_min 1,062 (-3) -0.28%
slices_inliner_min 4,905 (-14) -0.28%
regression_6674_1_inliner_zero 689 (-2) -0.29%
regression_6674_2_inliner_zero 689 (-2) -0.29%
regression_6674_2_inliner_min 686 (-2) -0.29%
regression_6674_1_inliner_max 678 (-2) -0.29%
regression_6674_2_inliner_max 678 (-2) -0.29%
regression_6674_1_inliner_min 660 (-2) -0.30%
array_sort_inliner_min 976 (-3) -0.31%
slices_inliner_zero 3,815 (-12) -0.31%
simple_shield_inliner_max 2,111 (-7) -0.33%
simple_shield_inliner_zero 2,111 (-7) -0.33%
slices_inliner_max 3,609 (-12) -0.33%
brillig_cow_inliner_min 1,184 (-4) -0.34%
regression_9860_inliner_max 583 (-2) -0.34%
regression_9860_inliner_min 583 (-2) -0.34%
regression_9860_inliner_zero 583 (-2) -0.34%
regression_8174_inliner_max 289 (-1) -0.34%
regression_8174_inliner_min 289 (-1) -0.34%
regression_8174_inliner_zero 289 (-1) -0.34%
array_sort_inliner_max 861 (-3) -0.35%
array_sort_inliner_zero 861 (-3) -0.35%
slice_loop_inliner_max 841 (-3) -0.36%
brillig_cow_assign_inliner_max 479 (-2) -0.42%
brillig_cow_assign_inliner_min 479 (-2) -0.42%
brillig_cow_assign_inliner_zero 479 (-2) -0.42%
array_to_slice_inliner_max 944 (-4) -0.42%
regression_10170_inliner_max 1,171 (-5) -0.43%
regression_10170_inliner_min 1,171 (-5) -0.43%
regression_10170_inliner_zero 1,171 (-5) -0.43%
merkle_insert_inliner_max 2,945 (-13) -0.44%
merkle_insert_inliner_zero 3,072 (-14) -0.45%
regression_9160_inliner_max 410 (-2) -0.49%
regression_9160_inliner_min 410 (-2) -0.49%
regression_9160_inliner_zero 410 (-2) -0.49%
array_len_inliner_max 199 (-1) -0.50%
array_len_inliner_min 199 (-1) -0.50%
array_len_inliner_zero 199 (-1) -0.50%
regression_struct_array_conditional_inliner_max 1,142 (-6) -0.52%
regression_struct_array_conditional_inliner_min 1,142 (-6) -0.52%
regression_struct_array_conditional_inliner_zero 1,142 (-6) -0.52%
last_uses_regression_8935_inliner_max 340 (-2) -0.58%
last_uses_regression_8935_inliner_min 340 (-2) -0.58%
last_uses_regression_8935_inliner_zero 340 (-2) -0.58%
regression_9758_inliner_min 168 (-1) -0.59%
regression_9758_inliner_zero 168 (-1) -0.59%
regression_9102_inliner_min 167 (-1) -0.60%
regression_9312_inliner_max 159 (-1) -0.63%
regression_9312_inliner_min 159 (-1) -0.63%
regression_9312_inliner_zero 159 (-1) -0.63%
regression_9102_inliner_max 155 (-1) -0.64%
regression_9102_inliner_zero 155 (-1) -0.64%
regression_9907_inliner_min 139 (-1) -0.71%
array_dedup_regression_inliner_max 665 (-5) -0.75%
array_dedup_regression_inliner_min 665 (-5) -0.75%
array_dedup_regression_inliner_zero 665 (-5) -0.75%
global_array_rc_regression_8259_inliner_max 132 (-1) -0.75%
global_array_rc_regression_8259_inliner_min 132 (-1) -0.75%
global_array_rc_regression_8259_inliner_zero 132 (-1) -0.75%
global_nested_array_regression_9270_inliner_min 262 (-2) -0.76%
brillig_rc_regression_6123_inliner_min 259 (-2) -0.77%
global_nested_array_regression_9270_inliner_max 250 (-2) -0.79%
global_nested_array_regression_9270_inliner_zero 250 (-2) -0.79%
regression_9907_inliner_max 124 (-1) -0.80%
regression_9907_inliner_zero 124 (-1) -0.80%
regression_9439_inliner_max 114 (-1) -0.87%
regression_9439_inliner_min 114 (-1) -0.87%
regression_9439_inliner_zero 114 (-1) -0.87%
array_rc_regression_7842_inliner_min 108 (-1) -0.92%
mutate_array_copy_inliner_min 107 (-1) -0.93%
regression_9725_2_inliner_min 103 (-1) -0.96%
simple_radix_inliner_max 67 (-1) -1.47%
simple_radix_inliner_min 67 (-1) -1.47%
simple_radix_inliner_zero 67 (-1) -1.47%

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: b761766 Previous: 2a27b18 Ratio
rollup-block-root-single-tx 0.003 s 0.002 s 1.50

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.

⚠️ 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: b761766 Previous: 2a27b18 Ratio
test_report_zkpassport_noir-ecdsa_ 2 s 1 s 2
test_report_zkpassport_noir_rsa_ 2 s 1 s 2

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

CC: @TomAFrench

@aakoshh aakoshh changed the title chore(audit): Minor refactorings in Brillig procedures chore(audit): Fix the decrease of ref-count in Brillig procedures and other refactors Oct 31, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Oct 31, 2025

Changes to circuit sizes

Generated at commit: 013f3fe2577bbb6e2e498503e5ddc7694a58bde8, compared to commit: 2a27b186687cab46e6976a68250833d63fd402ec

🧾 Summary (10% most significant diffs)

Program ACIR opcodes (+/-) % Circuit size (+/-) %
reference_counts_slices_inliner_0 +2 ❌ +20.00% +2,744 ❌ +5081.48%

Full diff report 👇
Program ACIR opcodes (+/-) % Circuit size (+/-) %
reference_counts_slices_inliner_0 12 (+2) +20.00% 2,798 (+2,744) +5081.48%

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

Benchmark suite Current: 7db34b7 Previous: 1324e73 Ratio
sha512-100-bytes 1.965 s 1.575 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.

Test Suite Duration

Details
Benchmark suite Current: b761766 Previous: 2a27b18 Ratio
test_report_AztecProtocol_aztec-packages_noir-projects_aztec-nr 131 s 117 s 1.12
test_report_AztecProtocol_aztec-packages_noir-projects_noir-contracts 177 s 156 s 1.13
test_report_AztecProtocol_aztec-packages_noir-projects_noir-protocol-circuits_crates_blob 386 s 414 s 0.93
test_report_AztecProtocol_aztec-packages_noir-projects_noir-protocol-circuits_crates_private-kernel-lib 295 s 296 s 1.00
test_report_AztecProtocol_aztec-packages_noir-projects_noir-protocol-circuits_crates_types 111 s 112 s 0.99
test_report_noir-lang_noir-bignum_ 162 s 163 s 0.99
test_report_noir-lang_noir_bigcurve_ 348 s 403 s 0.86
test_report_noir-lang_sha256_ 15 s 16 s 0.94
test_report_noir-lang_sha512_ 14 s 14 s 1
test_report_zkpassport_noir-ecdsa_ 2 s 1 s 2
test_report_zkpassport_noir_rsa_ 2 s 1 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.

Compilation Time

Details
Benchmark suite Current: b761766 Previous: 2a27b18 Ratio
private-kernel-inner 1.926 s 2.072 s 0.93
private-kernel-reset 7.722 s 7.782 s 0.99
private-kernel-tail 1.862 s 1.71 s 1.09
rollup-block-root-first-empty-tx 1.354 s 1.478 s 0.92
rollup-block-root-single-tx 1.37 s 1.4 s 0.98
rollup-block-root 1.39 s 1.4 s 0.99
rollup-checkpoint-merge 1.422 s 1.492 s 0.95
rollup-checkpoint-root-single-block 398 s 375 s 1.06
rollup-checkpoint-root 397 s 404 s 0.98
rollup-root 1.494 s 1.482 s 1.01
rollup-tx-base-private 19.9 s 21.92 s 0.91
rollup-tx-base-public 81.9 s 85.24 s 0.96
rollup-tx-merge 1.348 s 1.358 s 0.99
semaphore-depth-10 0.82 s 0.77 s 1.06
sha512-100-bytes 1.56 s 1.653 s 0.94

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: b761766 Previous: 2a27b18 Ratio
private-kernel-inner 267.81 MB 267.81 MB 1
private-kernel-reset 494.31 MB 494.31 MB 1
private-kernel-tail 237.69 MB 237.69 MB 1
rollup-block-root-first-empty-tx 334.33 MB 334.33 MB 1
rollup-block-root-single-tx 332.77 MB 332.77 MB 1
rollup-block-root 335.55 MB 335.56 MB 1.00
rollup-checkpoint-merge 335.53 MB 335.53 MB 1
rollup-checkpoint-root-single-block 11250 MB 11250 MB 1
rollup-checkpoint-root 11250 MB 11250 MB 1
rollup-root 337.06 MB 337.06 MB 1
rollup-tx-base-private 1070 MB 1070 MB 1
rollup-tx-base-public 3030 MB 3030 MB 1
rollup-tx-merge 332.35 MB 332.35 MB 1
semaphore_depth_10 92.32 MB 92.32 MB 1
sha512_100_bytes 185.61 MB 185.63 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: b761766 Previous: 2a27b18 Ratio
private-kernel-inner 257.39 MB 257.39 MB 1
private-kernel-reset 290.79 MB 290.79 MB 1
private-kernel-tail 237.86 MB 237.86 MB 1
rollup-block-root 333.67 MB 333.67 MB 1
rollup-checkpoint-merge 332.43 MB 332.43 MB 1
rollup-checkpoint-root-single-block 1760 MB 1760 MB 1
rollup-checkpoint-root 1760 MB 1760 MB 1
rollup-root 333.65 MB 333.65 MB 1
rollup-tx-base-private 521.11 MB 521.11 MB 1
rollup-tx-base-public 467.58 MB 467.58 MB 1
rollup-tx-merge 331.89 MB 331.89 MB 1
semaphore_depth_10 73.84 MB 73.84 MB 1
sha512_100_bytes 72.08 MB 72.08 MB 1

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

@aakoshh
Copy link
Contributor Author

aakoshh commented Nov 5, 2025

No noticeable change in memory. @vezenovm @TomAFrench do you have an opinion on whether its worth trying to decrement the ref-count at all?

@jfecher
Copy link
Contributor

jfecher commented Nov 5, 2025

@aakoshh what about for external repos? I'd think they may be more impacted.

That being said, this sounds related to when we removed DecRc from ssa-gen after discovering performance improved with it gone

@vezenovm
Copy link
Contributor

vezenovm commented Nov 5, 2025

@aakoshh what about for external repos? I'd think they may be more impacted.

Our benches do contain the external aztec protocol circuits if that is what you are referring to @jfecher.

@aakoshh I am not sure it is worth trying to decrement the RC at all. As we currently do not write the decremented RC back to the heap (which is incorrect) it looks like the decrement does not provide much of a benefit based off of the opcode diff. In fact, it looks like it mostly causes an opcode count degradation aside for radix decomposition. I am curious the results if we were to simply remove this decrement. I imagine it would be similar to our results from removing dec_rc from the SSA gen. We could just branch of off this PR to test that as I see you have lots of other cleanup / documentation as part of this PR.

@aakoshh
Copy link
Contributor Author

aakoshh commented Nov 5, 2025

@jfecher the “Execution Memory” and “Time” reports are based on the external repos, if that’s what you meant. They didn’t show any change.

By not doing decrement, we would save 2 opcodes in the bytecode size (in the procedures) and 2 opcodes in execution per copy we make. Intuitively once a copy is made, saving 2 opcodes shouldn’t make much of a difference.

OTOH if we decrease to 1 we might save a future copy. But that’s circumstantial.

@vezenovm
Copy link
Contributor

vezenovm commented Nov 5, 2025

By not doing decrement, we would save 2 opcodes in the bytecode size (in the procedures) and 2 opcodes in execution per copy we make. Intuitively once a copy is made, saving 2 opcodes shouldn’t make much of a difference.

OTOH if we decrease to 1 we might save a future copy. But that’s circumstantial.

Yeah it is very circumstantial and looks to be very unlikely. It also would be good for Brillig gen to be aligned with SSA gen. We can look at bringing back dec_rc more generally in the future.

@aakoshh
Copy link
Contributor Author

aakoshh commented Nov 5, 2025

Okay, I’ll open a follow up PR to remove it

@jfecher
Copy link
Contributor

jfecher commented Nov 5, 2025

Could be worth revisiting this in the future when ownership optimizations change since we still have more conceptual clones (inc_rcs) being inserted there.

@aakoshh aakoshh changed the title fix(brillig): Store decremented ref-count in array/vector copy and other refactors fix(brillig): Skip decrementing ref-count in array/vector copy and other refactors Nov 10, 2025
@aakoshh aakoshh requested a review from jfecher November 10, 2025 18:36
@jfecher jfecher added this pull request to the merge queue Nov 10, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to a conflict with the base branch Nov 10, 2025
@aakoshh aakoshh enabled auto-merge November 11, 2025 13:33
@aakoshh aakoshh added this pull request to the merge queue Nov 11, 2025
Merged via the queue into master with commit cf8602d Nov 11, 2025
132 checks passed
@aakoshh aakoshh deleted the af/audit-brillig-gen-5 branch November 11, 2025 14:18
github-merge-queue bot pushed a commit to AztecProtocol/aztec-packages that referenced this pull request Nov 12, 2025
Automated pull of nightly from the
[noir](https://github.com/noir-lang/noir) programming language, a
dependency of Aztec.
BEGIN_COMMIT_OVERRIDE
fix(frontend)!: Preserve int type when quoting tokens
(noir-lang/noir#10330)
fix: check overflow for Pedersen grumpkin scalars
(noir-lang/noir#10462)
chore(frontend): Various tests in elaborator expressions submodule and
minor refactors (noir-lang/noir#10475)
chore: bump external pinned commits
(noir-lang/noir#10477)
fix: disallow keywords in attributes
(noir-lang/noir#10473)
chore: refactor codegen_control_flow
(noir-lang/noir#10320)
fix: builtin with body now errors instead of crashing
(noir-lang/noir#10474)
fix: handle ambiguous trait methods in assumed traits
(noir-lang/noir#10468)
fix: force_substitute bindings during monomorphization for associated
constants (noir-lang/noir#10467)
fix(brillig): Skip decrementing ref-count in array/vector copy and other
refactors (noir-lang/noir#10335)
fix(ssa): Cast to `u64` when inserting OOB checks in DIE
(noir-lang/noir#10463)
fix: disallow comptime-only types in non-comptime globals
(noir-lang/noir#10458)
chore(fuzzing): fix default artifact for brillig target
(noir-lang/noir#10465)
END_COMMIT_OVERRIDE
github-merge-queue bot pushed a commit to AztecProtocol/aztec-packages that referenced this pull request Nov 12, 2025
Automated pull of nightly from the
[noir](https://github.com/noir-lang/noir) programming language, a
dependency of Aztec.
BEGIN_COMMIT_OVERRIDE
fix(frontend)!: Preserve int type when quoting tokens
(noir-lang/noir#10330)
fix: check overflow for Pedersen grumpkin scalars
(noir-lang/noir#10462)
chore(frontend): Various tests in elaborator expressions submodule and
minor refactors (noir-lang/noir#10475)
chore: bump external pinned commits
(noir-lang/noir#10477)
fix: disallow keywords in attributes
(noir-lang/noir#10473)
chore: refactor codegen_control_flow
(noir-lang/noir#10320)
fix: builtin with body now errors instead of crashing
(noir-lang/noir#10474)
fix: handle ambiguous trait methods in assumed traits
(noir-lang/noir#10468)
fix: force_substitute bindings during monomorphization for associated
constants (noir-lang/noir#10467)
fix(brillig): Skip decrementing ref-count in array/vector copy and other
refactors (noir-lang/noir#10335)
fix(ssa): Cast to `u64` when inserting OOB checks in DIE
(noir-lang/noir#10463)
fix: disallow comptime-only types in non-comptime globals
(noir-lang/noir#10458)
chore(fuzzing): fix default artifact for brillig target
(noir-lang/noir#10465)
END_COMMIT_OVERRIDE
github-merge-queue bot pushed a commit to AztecProtocol/aztec-packages that referenced this pull request Nov 12, 2025
Automated pull of nightly from the
[noir](https://github.com/noir-lang/noir) programming language, a
dependency of Aztec.
BEGIN_COMMIT_OVERRIDE
fix(frontend)!: Preserve int type when quoting tokens
(noir-lang/noir#10330)
fix: check overflow for Pedersen grumpkin scalars
(noir-lang/noir#10462)
chore(frontend): Various tests in elaborator expressions submodule and
minor refactors (noir-lang/noir#10475)
chore: bump external pinned commits
(noir-lang/noir#10477)
fix: disallow keywords in attributes
(noir-lang/noir#10473)
chore: refactor codegen_control_flow
(noir-lang/noir#10320)
fix: builtin with body now errors instead of crashing
(noir-lang/noir#10474)
fix: handle ambiguous trait methods in assumed traits
(noir-lang/noir#10468)
fix: force_substitute bindings during monomorphization for associated
constants (noir-lang/noir#10467)
fix(brillig): Skip decrementing ref-count in array/vector copy and other
refactors (noir-lang/noir#10335)
fix(ssa): Cast to `u64` when inserting OOB checks in DIE
(noir-lang/noir#10463)
fix: disallow comptime-only types in non-comptime globals
(noir-lang/noir#10458)
chore(fuzzing): fix default artifact for brillig target
(noir-lang/noir#10465)
END_COMMIT_OVERRIDE
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

Development

Successfully merging this pull request may close these issues.

4 participants