Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(brillig): Hoist shared constants across functions to the global space #7216

Open
wants to merge 20 commits into
base: master
Choose a base branch
from

Conversation

vezenovm
Copy link
Contributor

@vezenovm vezenovm commented Jan 28, 2025

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.

  1. When building our BrilligGlobals context structure we now maintain a new map:
/// Maps entry point to constants 
hoisted_global_constants: HashMap<FunctionId, ConstantCounterMap>,
/// Mapping of a constant value and the number of functions in which it occurs
pub(crate) type ConstantCounterMap = HashMap<(FieldElement, NumericType), usize>;
  1. NB: I re-computed ConstantAllocation to determine which constant appears in both functions. This was technically recomputed as we calculate a ConstantAllocation when creating a FunctionContext. 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.
  2. When compiling globals, we fetch the constants which appear in more than one function.
  3. After compiling the user specified globals, we compile the hoisted global constants.
  4. Maintain a separate map for entry points to their hoisted globals:
/// Final map that associates an entry point with any local function constants
/// that are shared and were hoisted to the global space.
/// This map is kept separate from `entry_point_globals_map` to clearly distinguish
/// the two types of globals.
entry_point_hoisted_globals_map: HashMap<FunctionId, HoistedConstantsToBrilligGlobals>,
pub(crate) type HoistedConstantsToBrilligGlobals =
    HashMap<(FieldElement, NumericType), BrilligVariable>;
  1. When compiling regular Brillig blocks we gate liveness analysis on checking whether a variable is actually a hoisted constant, not only on dfg.is_global.
  2. When converting a variable we escape early if it is a hoisted constant.

Additional Context

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 marked this pull request as draft January 28, 2025 22:57
Copy link
Contributor

github-actions bot commented Jan 28, 2025

Changes to Brillig bytecode sizes

Generated at commit: d670db3be57b194cd74cd669163df4a8155ead73, compared to commit: 15bbaa86bde37546f69e3e7b375e10b569972bd3

🧾 Summary (10% most significant diffs)

Program Brillig opcodes (+/-) %
trait_impl_base_type_inliner_min -10 ✅ -4.00%
brillig_calls_array_inliner_min -9 ✅ -4.09%
regression_unsafe_no_predicates_inliner_min -4 ✅ -4.35%
uhashmap_inliner_zero -328 ✅ -4.39%
brillig_calls_conditionals_inliner_min -6 ✅ -4.48%
brillig_calls_conditionals_inliner_zero -6 ✅ -4.48%
references_inliner_min -20 ✅ -4.75%
slices_inliner_min -122 ✅ -4.84%
simple_print_inliner_min -12 ✅ -5.17%
regression_3051_inliner_min -10 ✅ -5.18%
higher_order_functions_inliner_min -75 ✅ -5.61%
brillig_calls_inliner_min -11 ✅ -5.70%
reference_counts_inliner_zero -40 ✅ -6.03%
hashmap_inliner_min -618 ✅ -6.31%
uhashmap_inliner_min -532 ✅ -6.39%
debug_logs_inliner_min -763 ✅ -7.82%
reference_counts_inliner_min -69 ✅ -8.22%
prelude_inliner_min -19 ✅ -8.37%

Full diff report 👇
Program Brillig opcodes (+/-) %
hashmap_inliner_max 19,649 (-14) -0.07%
u128_inliner_max 2,655 (-3) -0.11%
keccak256_inliner_zero 1,967 (-3) -0.15%
nested_array_dynamic_inliner_min 1,853 (-3) -0.16%
nested_array_dynamic_inliner_zero 1,853 (-3) -0.16%
keccak256_inliner_min 1,665 (-3) -0.18%
sha2_byte_inliner_zero 2,205 (-4) -0.18%
regression_inliner_zero 961 (-2) -0.21%
ram_blowup_regression_inliner_zero 943 (-2) -0.21%
modulus_inliner_min 1,761 (-5) -0.28%
array_dynamic_blackbox_input_inliner_zero 1,021 (-3) -0.29%
nested_array_in_slice_inliner_min 982 (-3) -0.30%
nested_array_in_slice_inliner_zero 982 (-3) -0.30%
poseidon_bn254_hash_width_3_inliner_zero 4,649 (-15) -0.32%
poseidon_bn254_hash_inliner_zero 4,649 (-15) -0.32%
ecdsa_secp256k1_inliner_zero 910 (-3) -0.33%
brillig_cow_regression_inliner_zero 2,082 (-7) -0.34%
array_dynamic_nested_blackbox_input_inliner_zero 887 (-3) -0.34%
wildcard_type_inliner_min 288 (-1) -0.35%
poseidonsponge_x5_254_inliner_zero 2,983 (-11) -0.37%
array_dedup_regression_inliner_min 264 (-1) -0.38%
regression_5252_inliner_zero 3,343 (-14) -0.42%
brillig_cow_inliner_zero 238 (-1) -0.42%
sha256_brillig_performance_regression_inliner_zero 1,666 (-7) -0.42%
conditional_1_inliner_zero 1,116 (-5) -0.45%
regression_4449_inliner_zero 765 (-4) -0.52%
to_le_bytes_inliner_min 166 (-1) -0.60%
6_inliner_zero 830 (-5) -0.60%
array_dynamic_inliner_min 326 (-2) -0.61%
slice_coercion_inliner_min 486 (-3) -0.61%
uhashmap_inliner_max 12,480 (-78) -0.62%
assert_inliner_min 160 (-1) -0.62%
generics_inliner_zero 160 (-1) -0.62%
sha256_var_witness_const_regression_inliner_zero 798 (-5) -0.62%
conditional_regression_661_inliner_zero 157 (-1) -0.63%
poseidonsponge_x5_254_inliner_min 3,134 (-20) -0.63%
7_inliner_min 153 (-1) -0.65%
blake3_inliner_min 153 (-1) -0.65%
brillig_blake2s_inliner_min 150 (-1) -0.66%
array_sort_inliner_max 290 (-2) -0.68%
array_sort_inliner_zero 290 (-2) -0.68%
bench_2_to_17_inliner_zero 288 (-2) -0.69%
aes128_encrypt_inliner_min 431 (-3) -0.69%
bigint_inliner_zero 1,856 (-14) -0.75%
poseidon_bn254_hash_width_3_inliner_min 4,984 (-38) -0.76%
poseidon_bn254_hash_inliner_min 4,984 (-38) -0.76%
sha256_regression_inliner_zero 4,811 (-37) -0.76%
conditional_regression_short_circuit_inliner_zero 910 (-7) -0.76%
aes128_encrypt_inliner_zero 385 (-3) -0.77%
side_effects_constrain_array_inliner_min 123 (-1) -0.81%
side_effects_constrain_array_inliner_zero 123 (-1) -0.81%
array_to_slice_inliner_zero 737 (-6) -0.81%
embedded_curve_ops_inliner_zero 358 (-3) -0.83%
binary_operator_overloading_inliner_min 355 (-3) -0.84%
slice_regex_inliner_zero 1,643 (-14) -0.84%
to_bytes_integration_inliner_min 221 (-2) -0.90%
sha256_var_size_regression_inliner_zero 1,085 (-10) -0.91%
sha256_brillig_performance_regression_inliner_min 1,830 (-17) -0.92%
brillig_cow_inliner_min 318 (-3) -0.93%
array_eq_inliner_min 105 (-1) -0.94%
reference_only_used_as_alias_inliner_min 312 (-3) -0.95%
slice_loop_inliner_zero 311 (-3) -0.96%
bigint_inliner_min 1,969 (-19) -0.96%
fold_distinct_return_inliner_min 101 (-1) -0.98%
poseidon2_inliner_zero 295 (-3) -1.01%
slices_inliner_zero 2,062 (-22) -1.06%
fold_complex_outputs_inliner_zero 521 (-6) -1.14%
struct_inputs_inliner_zero 248 (-3) -1.20%
derive_inliner_zero 329 (-4) -1.20%
regression_5252_inliner_min 3,528 (-43) -1.20%
conditional_regression_661_inliner_min 162 (-2) -1.22%
fold_2_to_17_inliner_zero 397 (-5) -1.24%
brillig_cow_regression_inliner_min 2,312 (-30) -1.28%
tuple_inputs_inliner_min 306 (-4) -1.29%
tuple_inputs_inliner_zero 306 (-4) -1.29%
strings_inliner_zero 913 (-12) -1.30%
ecdsa_secp256k1_inliner_min 1,203 (-16) -1.31%
binary_operator_overloading_inliner_zero 225 (-3) -1.32%
simple_2d_array_inliner_min 144 (-2) -1.37%
loop_invariant_regression_inliner_min 143 (-2) -1.38%
sha2_byte_inliner_min 2,956 (-42) -1.40%
array_sort_inliner_min 350 (-5) -1.41%
brillig_arrays_inliner_min 140 (-2) -1.41%
sha256_var_padding_regression_inliner_zero 2,886 (-42) -1.43%
pedersen_check_inliner_min 549 (-8) -1.44%
brillig_pedersen_inliner_min 549 (-8) -1.44%
conditional_1_inliner_min 1,399 (-21) -1.48%
ram_blowup_regression_inliner_min 1,122 (-17) -1.49%
sha256_var_size_regression_inliner_min 1,226 (-19) -1.53%
6_inliner_min 1,000 (-16) -1.57%
brillig_calls_array_inliner_zero 184 (-3) -1.60%
sha256_var_witness_const_regression_inliner_min 974 (-16) -1.62%
array_dynamic_nested_blackbox_input_inliner_min 1,186 (-20) -1.66%
regression_inliner_min 1,103 (-19) -1.69%
regression_6734_inliner_min 58 (-1) -1.69%
struct_inputs_inliner_min 287 (-5) -1.71%
array_dynamic_blackbox_input_inliner_min 1,259 (-22) -1.72%
to_be_bytes_inliner_min 224 (-4) -1.75%
debug_logs_inliner_zero 5,327 (-96) -1.77%
regression_4449_inliner_min 1,053 (-19) -1.77%
conditional_regression_short_circuit_inliner_min 1,097 (-20) -1.79%
regression_4124_inliner_min 54 (-1) -1.82%
loop_inliner_min 108 (-2) -1.82%
conditional_2_inliner_min 161 (-3) -1.83%
slice_loop_inliner_min 321 (-6) -1.83%
sha256_regression_inliner_min 5,189 (-98) -1.85%
higher_order_functions_inliner_zero 703 (-14) -1.95%
generics_inliner_min 239 (-5) -2.05%
no_predicates_numeric_generic_poseidon_inliner_zero 562 (-12) -2.09%
fold_numeric_generic_poseidon_inliner_zero 562 (-12) -2.09%
7_function_inliner_zero 507 (-11) -2.12%
brillig_conditional_inliner_min 45 (-1) -2.17%
brillig_rc_regression_6123_inliner_min 225 (-5) -2.17%
hint_black_box_inliner_zero 358 (-8) -2.19%
conditional_regression_547_inliner_min 44 (-1) -2.22%
hash_to_field_inliner_min 211 (-5) -2.31%
regression_6674_1_inliner_min 292 (-7) -2.34%
sha256_inliner_zero 1,205 (-29) -2.35%
sha256_inliner_min 1,362 (-33) -2.37%
hint_black_box_inliner_min 368 (-9) -2.39%
global_var_regression_simple_inliner_min 163 (-4) -2.40%
slice_regex_inliner_min 2,066 (-52) -2.46%
7_function_inliner_min 632 (-16) -2.47%
brillig_nested_arrays_inliner_zero 235 (-6) -2.49%
brillig_nested_arrays_inliner_min 268 (-7) -2.55%
u128_inliner_zero 1,905 (-52) -2.66%
simple_shield_inliner_min 838 (-23) -2.67%
nested_arrays_from_brillig_inliner_min 182 (-5) -2.67%
regression_11294_inliner_min 471 (-13) -2.69%
sha256_var_padding_regression_inliner_min 3,128 (-88) -2.74%
global_consts_inliner_min 246 (-7) -2.77%
regression_bignum_inliner_min 351 (-10) -2.77%
references_inliner_zero 240 (-7) -2.83%
regression_6674_3_inliner_min 842 (-25) -2.88%
fold_numeric_generic_poseidon_inliner_min 616 (-19) -2.99%
no_predicates_numeric_generic_poseidon_inliner_min 616 (-19) -2.99%
trait_impl_base_type_inliner_zero 64 (-2) -3.03%
fold_complex_outputs_inliner_min 685 (-22) -3.11%
regression_5045_inliner_min 217 (-7) -3.13%
regression_6674_2_inliner_min 296 (-10) -3.27%
inline_decompose_hint_brillig_call_inliner_min 235 (-8) -3.29%
fmtstr_with_global_inliner_min 117 (-4) -3.31%
fold_2_to_17_inliner_min 388 (-14) -3.48%
bench_2_to_17_inliner_min 357 (-13) -3.51%
slice_dynamic_index_inliner_min 2,688 (-98) -3.52%
u128_inliner_min 2,183 (-80) -3.54%
brillig_acir_as_brillig_inliner_min 109 (-4) -3.54%
derive_inliner_min 572 (-21) -3.54%
embedded_curve_ops_inliner_min 496 (-19) -3.69%
poseidon2_inliner_min 364 (-14) -3.70%
array_to_slice_inliner_min 966 (-38) -3.78%
hashmap_inliner_zero 7,526 (-309) -3.94%
strings_inliner_min 1,093 (-45) -3.95%
trait_impl_base_type_inliner_min 240 (-10) -4.00%
brillig_calls_array_inliner_min 211 (-9) -4.09%
regression_unsafe_no_predicates_inliner_min 88 (-4) -4.35%
uhashmap_inliner_zero 7,140 (-328) -4.39%
brillig_calls_conditionals_inliner_min 128 (-6) -4.48%
brillig_calls_conditionals_inliner_zero 128 (-6) -4.48%
references_inliner_min 401 (-20) -4.75%
slices_inliner_min 2,401 (-122) -4.84%
simple_print_inliner_min 220 (-12) -5.17%
regression_3051_inliner_min 183 (-10) -5.18%
higher_order_functions_inliner_min 1,262 (-75) -5.61%
brillig_calls_inliner_min 182 (-11) -5.70%
reference_counts_inliner_zero 623 (-40) -6.03%
hashmap_inliner_min 9,173 (-618) -6.31%
uhashmap_inliner_min 7,798 (-532) -6.39%
debug_logs_inliner_min 8,988 (-763) -7.82%
reference_counts_inliner_min 770 (-69) -8.22%
prelude_inliner_min 208 (-19) -8.37%

Copy link
Contributor

github-actions bot commented Jan 28, 2025

Changes to number of Brillig opcodes executed

Generated at commit: d670db3be57b194cd74cd669163df4a8155ead73, compared to commit: 15bbaa86bde37546f69e3e7b375e10b569972bd3

🧾 Summary (10% most significant diffs)

Program Brillig opcodes (+/-) %
regression_5045_inliner_min +3 ❌ +13.64%
regression_unsafe_no_predicates_inliner_min +2 ❌ +8.33%
brillig_nested_arrays_inliner_min -20 ✅ -4.09%
references_inliner_min -27 ✅ -4.21%
brillig_calls_array_inliner_min -12 ✅ -4.46%
higher_order_functions_inliner_min -103 ✅ -4.53%
strings_inliner_min -138 ✅ -4.77%
regression_3051_inliner_min -10 ✅ -4.98%
simple_print_inliner_min -12 ✅ -5.00%
inline_decompose_hint_brillig_call_inliner_min -14 ✅ -5.11%
embedded_curve_ops_inliner_min -37 ✅ -5.56%
brillig_calls_inliner_min -11 ✅ -5.82%
brillig_calls_conditionals_inliner_min -14 ✅ -7.07%
brillig_calls_conditionals_inliner_zero -14 ✅ -7.07%
reference_counts_inliner_min -73 ✅ -7.53%
debug_logs_inliner_min -814 ✅ -7.89%
reference_counts_inliner_zero -58 ✅ -8.04%
prelude_inliner_min -19 ✅ -8.09%

Full diff report 👇
Program Brillig opcodes (+/-) %
regression_5045_inliner_min 25 (+3) +13.64%
regression_unsafe_no_predicates_inliner_min 26 (+2) +8.33%
global_var_regression_entry_points_inliner_min 135,428 (-4) -0.00%
modulus_inliner_min 18,016 (-5) -0.03%
keccak256_inliner_min 32,061 (-9) -0.03%
keccak256_inliner_zero 31,680 (-9) -0.03%
to_bytes_integration_inliner_min 4,239 (-2) -0.05%
poseidonsponge_x5_254_inliner_zero 201,869 (-121) -0.06%
regression_5252_inliner_zero 1,006,342 (-647) -0.06%
array_eq_inliner_min 1,202 (-1) -0.08%
7_inliner_min 1,061 (-1) -0.09%
blake3_inliner_min 1,061 (-1) -0.09%
brillig_blake2s_inliner_min 1,058 (-1) -0.09%
aes128_encrypt_inliner_zero 3,072 (-3) -0.10%
loop_invariant_regression_inliner_min 1,665 (-2) -0.12%
poseidon_bn254_hash_inliner_zero 181,986 (-229) -0.13%
poseidon_bn254_hash_width_3_inliner_zero 181,986 (-229) -0.13%
regression_inliner_zero 2,710 (-4) -0.15%
aes128_encrypt_inliner_min 3,476 (-6) -0.17%
poseidonsponge_x5_254_inliner_min 205,956 (-369) -0.18%
hashmap_inliner_max 48,199 (-88) -0.18%
to_be_bytes_inliner_min 2,124 (-4) -0.19%
regression_5252_inliner_min 1,029,260 (-2,010) -0.19%
wildcard_type_inliner_min 447 (-1) -0.22%
poseidon_bn254_hash_inliner_min 185,115 (-600) -0.32%
poseidon_bn254_hash_width_3_inliner_min 185,115 (-600) -0.32%
brillig_cow_inliner_zero 800 (-3) -0.37%
array_dynamic_inliner_min 505 (-2) -0.39%
array_dedup_regression_inliner_min 1,227 (-5) -0.41%
global_consts_inliner_min 1,690 (-7) -0.41%
array_dynamic_nested_blackbox_input_inliner_zero 4,471 (-22) -0.49%
hash_to_field_inliner_min 963 (-5) -0.52%
bench_2_to_17_inliner_zero 609,451 (-3,268) -0.53%
sha256_var_witness_const_regression_inliner_zero 6,920 (-39) -0.56%
conditional_1_inliner_zero 5,480 (-31) -0.56%
brillig_cow_inliner_min 1,407 (-8) -0.57%
reference_only_used_as_alias_inliner_min 472 (-3) -0.63%
slice_coercion_inliner_min 469 (-3) -0.64%
conditional_regression_661_inliner_zero 148 (-1) -0.67%
regression_inliner_min 3,042 (-21) -0.69%
side_effects_constrain_array_inliner_min 135 (-1) -0.74%
side_effects_constrain_array_inliner_zero 135 (-1) -0.74%
array_sort_inliner_max 515 (-4) -0.77%
array_sort_inliner_zero 515 (-4) -0.77%
assert_inliner_min 127 (-1) -0.78%
poseidon2_inliner_zero 723 (-6) -0.82%
6_inliner_zero 4,403 (-37) -0.83%
fold_distinct_return_inliner_min 118 (-1) -0.84%
slices_inliner_zero 3,563 (-31) -0.86%
conditional_regression_short_circuit_inliner_zero 4,481 (-39) -0.86%
array_dynamic_nested_blackbox_input_inliner_min 4,904 (-44) -0.89%
sha256_var_witness_const_regression_inliner_min 7,687 (-71) -0.92%
slice_loop_inliner_zero 1,255 (-12) -0.95%
ram_blowup_regression_inliner_zero 806,321 (-8,205) -1.01%
struct_inputs_inliner_zero 586 (-6) -1.01%
simple_shield_inliner_min 2,552 (-27) -1.05%
brillig_cow_regression_inliner_min 538,281 (-5,711) -1.05%
sha2_byte_inliner_zero 71,567 (-761) -1.05%
brillig_cow_regression_inliner_zero 534,712 (-5,686) -1.05%
ram_blowup_regression_inliner_min 810,049 (-8,736) -1.07%
conditional_1_inliner_min 5,914 (-64) -1.07%
array_to_slice_inliner_zero 1,937 (-21) -1.07%
u128_inliner_max 23,973 (-276) -1.14%
brillig_arrays_inliner_min 171 (-2) -1.16%
sha256_brillig_performance_regression_inliner_zero 26,142 (-306) -1.16%
loop_inliner_min 170 (-2) -1.16%
slice_loop_inliner_min 1,269 (-15) -1.17%
simple_2d_array_inliner_min 169 (-2) -1.17%
array_sort_inliner_min 670 (-8) -1.18%
sha256_brillig_performance_regression_inliner_min 26,533 (-318) -1.18%
6_inliner_min 4,798 (-58) -1.19%
struct_inputs_inliner_min 654 (-8) -1.21%
sha256_inliner_min 12,154 (-149) -1.21%
conditional_regression_661_inliner_min 163 (-2) -1.21%
conditional_regression_short_circuit_inliner_min 4,901 (-61) -1.23%
7_function_inliner_zero 2,409 (-30) -1.23%
sha256_inliner_zero 11,218 (-140) -1.23%
binary_operator_overloading_inliner_min 397 (-5) -1.24%
regression_4449_inliner_zero 224,384 (-2,870) -1.26%
conditional_2_inliner_min 156 (-2) -1.27%
uhashmap_inliner_max 135,363 (-1,742) -1.27%
brillig_pedersen_inliner_min 920 (-12) -1.29%
pedersen_check_inliner_min 920 (-12) -1.29%
fold_complex_outputs_inliner_zero 902 (-12) -1.31%
generics_inliner_zero 222 (-3) -1.33%
regression_6674_1_inliner_min 1,030 (-15) -1.44%
nested_array_dynamic_inliner_min 3,484 (-51) -1.44%
nested_array_dynamic_inliner_zero 3,484 (-51) -1.44%
embedded_curve_ops_inliner_zero 402 (-6) -1.47%
7_function_inliner_min 2,583 (-39) -1.49%
ecdsa_secp256k1_inliner_zero 7,495 (-117) -1.54%
regression_4449_inliner_min 264,145 (-4,198) -1.56%
regression_11294_inliner_min 1,802 (-29) -1.58%
regression_6734_inliner_min 62 (-1) -1.59%
array_dynamic_blackbox_input_inliner_zero 20,922 (-348) -1.64%
nested_array_in_slice_inliner_min 1,691 (-30) -1.74%
nested_array_in_slice_inliner_zero 1,691 (-30) -1.74%
debug_logs_inliner_zero 5,351 (-96) -1.76%
slice_dynamic_index_inliner_min 4,887 (-89) -1.79%
hint_black_box_inliner_zero 979 (-18) -1.81%
regression_6674_2_inliner_min 1,032 (-19) -1.81%
derive_inliner_zero 325 (-6) -1.81%
regression_bignum_inliner_min 541 (-10) -1.81%
regression_4124_inliner_min 54 (-1) -1.82%
tuple_inputs_inliner_min 635 (-12) -1.85%
tuple_inputs_inliner_zero 635 (-12) -1.85%
sha2_byte_inliner_min 87,768 (-1,667) -1.86%
global_var_regression_simple_inliner_min 210 (-4) -1.87%
hint_black_box_inliner_min 993 (-19) -1.88%
brillig_rc_regression_6123_inliner_min 352 (-7) -1.95%
slice_regex_inliner_zero 3,868 (-78) -1.98%
brillig_nested_arrays_inliner_zero 295 (-6) -1.99%
regression_6674_3_inliner_min 1,966 (-40) -1.99%
ecdsa_secp256k1_inliner_min 8,027 (-165) -2.01%
fold_numeric_generic_poseidon_inliner_zero 5,603 (-116) -2.03%
no_predicates_numeric_generic_poseidon_inliner_zero 5,603 (-116) -2.03%
fold_numeric_generic_poseidon_inliner_min 5,670 (-122) -2.11%
no_predicates_numeric_generic_poseidon_inliner_min 5,670 (-122) -2.11%
higher_order_functions_inliner_zero 1,288 (-28) -2.13%
generics_inliner_min 321 (-7) -2.13%
binary_operator_overloading_inliner_zero 225 (-5) -2.17%
array_dynamic_blackbox_input_inliner_min 21,873 (-489) -2.19%
nested_arrays_from_brillig_inliner_min 217 (-5) -2.25%
uhashmap_inliner_zero 171,178 (-3,955) -2.26%
bench_2_to_17_inliner_min 696,073 (-16,342) -2.29%
fold_2_to_17_inliner_min 1,323,968 (-31,089) -2.29%
fold_2_to_17_inliner_zero 1,286,553 (-31,069) -2.36%
array_to_slice_inliner_min 2,194 (-53) -2.36%
brillig_conditional_inliner_min 41 (-1) -2.38%
conditional_regression_547_inliner_min 41 (-1) -2.38%
slice_regex_inliner_min 8,372 (-208) -2.42%
hashmap_inliner_zero 72,697 (-1,905) -2.55%
fold_complex_outputs_inliner_min 1,057 (-28) -2.58%
poseidon2_inliner_min 850 (-23) -2.63%
brillig_calls_array_inliner_zero 218 (-6) -2.68%
trait_impl_base_type_inliner_zero 68 (-2) -2.86%
uhashmap_inliner_min 191,040 (-5,941) -3.02%
strings_inliner_zero 2,014 (-63) -3.03%
slices_inliner_min 4,148 (-130) -3.04%
derive_inliner_min 596 (-19) -3.09%
sha256_var_size_regression_inliner_min 21,427 (-713) -3.22%
sha256_var_size_regression_inliner_zero 20,702 (-689) -3.22%
fmtstr_with_global_inliner_min 120 (-4) -3.23%
sha256_var_padding_regression_inliner_zero 222,876 (-7,531) -3.27%
sha256_var_padding_regression_inliner_min 224,255 (-7,663) -3.30%
brillig_acir_as_brillig_inliner_min 113 (-4) -3.42%
u128_inliner_min 46,788 (-1,695) -3.50%
hashmap_inliner_min 87,164 (-3,198) -3.54%
references_inliner_zero 380 (-14) -3.55%
sha256_regression_inliner_zero 149,647 (-5,676) -3.65%
sha256_regression_inliner_min 151,721 (-5,773) -3.67%
trait_impl_base_type_inliner_min 253 (-10) -3.80%
u128_inliner_zero 39,367 (-1,577) -3.85%
brillig_nested_arrays_inliner_min 469 (-20) -4.09%
references_inliner_min 615 (-27) -4.21%
brillig_calls_array_inliner_min 257 (-12) -4.46%
higher_order_functions_inliner_min 2,170 (-103) -4.53%
strings_inliner_min 2,758 (-138) -4.77%
regression_3051_inliner_min 191 (-10) -4.98%
simple_print_inliner_min 228 (-12) -5.00%
inline_decompose_hint_brillig_call_inliner_min 260 (-14) -5.11%
embedded_curve_ops_inliner_min 629 (-37) -5.56%
brillig_calls_inliner_min 178 (-11) -5.82%
brillig_calls_conditionals_inliner_min 184 (-14) -7.07%
brillig_calls_conditionals_inliner_zero 184 (-14) -7.07%
reference_counts_inliner_min 897 (-73) -7.53%
debug_logs_inliner_min 9,503 (-814) -7.89%
reference_counts_inliner_zero 663 (-58) -8.04%
prelude_inliner_min 216 (-19) -8.09%

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: 2940cc3 Previous: 15bbaa8 Ratio
noir-lang_noir_check_shuffle_ 1 s 0 s +∞

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 '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

@vezenovm vezenovm marked this pull request as ready for review January 30, 2025 13:06
@vezenovm vezenovm requested a review from a team January 30, 2025 13:12
@TomAFrench
Copy link
Member

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.

@vezenovm
Copy link
Contributor Author

vezenovm commented Jan 30, 2025

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.

  1. To avoid having to alter the globals graph for every function and the cloning cost that comes with it. We would also have to add the ability to mutate the normal function DFG. This feels like a leakage for a Brillig exclusive feature.
  2. I also wanted to re-use some of the pre-existing Brillig constant analysis tools.
  3. Doing this during our existing Brillig globals generation we could avoid another SSA pass or making a pre-existing complex more complex (as each pass is currently per-function).

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Hoist constants shared across functions into the global space
3 participants