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(ssa): Globals DIE #7081

Merged
merged 8 commits into from
Jan 16, 2025
Merged

Conversation

vezenovm
Copy link
Contributor

@vezenovm vezenovm commented Jan 15, 2025

Description

Problem*

Resolves #7021 (comment)

Summary*

DIE for globals is a little bit more funky as we do not have a mutable instructions vector as part of a block. We could do this but I would like to move away from re-using the entire Function/DataFlowGraph construct for globals which are much simpler than our functions.

We also want to account for numeric constants among our unused globals as declaring them in Brillig gen comes with a cost. Our current DIE only looks at instruction results, but we want to look at both instruction results and values representing constants.

Additional Context

I don't expect this PR to fully revert the regressions we see in #7021 due to the overhead for the global initialization call/return.

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.

Copy link
Contributor

github-actions bot commented Jan 15, 2025

Changes to Brillig bytecode sizes

Generated at commit: 5b2bd32d506ff9c3366574ca5a1ecb7cec5a604e, compared to commit: 22cc6519ef47515bceeecbef45e5ae9b29dfbdf8

🧾 Summary (10% most significant diffs)

Program Brillig opcodes (+/-) %
integer_array_indexing_inliner_max -1 ✅ -1.56%
integer_array_indexing_inliner_min -1 ✅ -1.56%
integer_array_indexing_inliner_zero -1 ✅ -1.56%
global_var_regression_simple_inliner_min -4 ✅ -1.67%
global_var_regression_simple_inliner_max -4 ✅ -2.94%
global_var_regression_simple_inliner_zero -4 ✅ -2.94%
global_consts_inliner_min -28 ✅ -8.14%
global_consts_inliner_max -28 ✅ -11.62%
global_consts_inliner_zero -28 ✅ -11.62%
inline_decompose_hint_brillig_call_inliner_max -4 ✅ -15.38%
inline_decompose_hint_brillig_call_inliner_zero -4 ✅ -15.38%

Full diff report 👇
Program Brillig opcodes (+/-) %
regression_4709_inliner_min 133,809 (-4) -0.00%
regression_4709_inliner_max 133,731 (-4) -0.00%
regression_4709_inliner_zero 133,731 (-4) -0.00%
hashmap_inliner_max 19,783 (-4) -0.02%
uhashmap_inliner_max 12,715 (-4) -0.03%
hashmap_inliner_min 12,634 (-4) -0.03%
u128_inliner_max 2,689 (-1) -0.04%
uhashmap_inliner_min 9,829 (-4) -0.04%
u128_inliner_min 2,415 (-1) -0.04%
keccak256_inliner_max 2,090 (-1) -0.05%
u128_inliner_zero 2,001 (-1) -0.05%
hashmap_inliner_zero 7,972 (-4) -0.05%
uhashmap_inliner_zero 7,557 (-4) -0.05%
sha256_regression_inliner_max 6,680 (-5) -0.07%
regression_inliner_min 1,325 (-1) -0.08%
sha256_regression_inliner_min 5,328 (-5) -0.09%
sha256_var_padding_regression_inliner_max 4,907 (-5) -0.10%
sha256_regression_inliner_zero 4,863 (-5) -0.10%
regression_inliner_zero 963 (-1) -0.10%
regression_inliner_max 926 (-1) -0.11%
sha256_var_padding_regression_inliner_min 3,274 (-5) -0.15%
sha2_byte_inliner_min 3,083 (-5) -0.16%
brillig_cow_regression_inliner_min 2,445 (-4) -0.16%
sha256_var_padding_regression_inliner_zero 2,956 (-5) -0.17%
brillig_cow_regression_inliner_zero 2,096 (-4) -0.19%
strings_inliner_zero 984 (-2) -0.20%
strings_inliner_max 936 (-2) -0.21%
sha256_inliner_max 2,288 (-5) -0.22%
brillig_cow_regression_inliner_max 2,060 (-5) -0.24%
sha2_byte_inliner_zero 2,766 (-7) -0.25%
sha256_brillig_performance_regression_inliner_min 1,921 (-5) -0.26%
sha2_byte_inliner_max 2,679 (-7) -0.26%
sha256_brillig_performance_regression_inliner_zero 1,673 (-5) -0.30%
sha256_var_size_regression_inliner_max 1,668 (-5) -0.30%
ram_blowup_regression_inliner_min 1,179 (-4) -0.34%
conditional_1_inliner_min 1,455 (-5) -0.34%
sha256_inliner_min 1,455 (-5) -0.34%
sha256_brillig_performance_regression_inliner_max 1,621 (-6) -0.37%
array_dynamic_blackbox_input_inliner_min 1,321 (-5) -0.38%
sha256_var_size_regression_inliner_min 1,288 (-5) -0.39%
sha256_inliner_zero 1,260 (-5) -0.40%
ecdsa_secp256k1_inliner_min 1,259 (-5) -0.40%
sha256_var_witness_const_regression_inliner_max 1,252 (-5) -0.40%
array_dynamic_nested_blackbox_input_inliner_min 1,246 (-5) -0.40%
ram_blowup_regression_inliner_zero 948 (-4) -0.42%
conditional_regression_short_circuit_inliner_min 1,177 (-5) -0.42%
ram_blowup_regression_inliner_max 932 (-4) -0.43%
regression_4449_inliner_min 1,112 (-5) -0.45%
sha256_var_size_regression_inliner_zero 1,098 (-5) -0.45%
6_inliner_min 1,063 (-5) -0.47%
sha256_var_witness_const_regression_inliner_min 1,031 (-5) -0.48%
array_dynamic_blackbox_input_inliner_zero 1,025 (-5) -0.49%
array_dynamic_blackbox_input_inliner_max 1,008 (-5) -0.49%
conditional_regression_short_circuit_inliner_max 1,210 (-7) -0.58%
6_inliner_max 1,137 (-7) -0.61%
conditional_1_inliner_max 1,137 (-7) -0.61%
sha256_var_witness_const_regression_inliner_zero 806 (-5) -0.62%
conditional_1_inliner_zero 1,127 (-7) -0.62%
ecdsa_secp256k1_inliner_zero 914 (-7) -0.76%
fold_call_witness_condition_inliner_min 128 (-1) -0.78%
array_dynamic_nested_blackbox_input_inliner_zero 891 (-7) -0.78%
ecdsa_secp256k1_inliner_max 881 (-7) -0.79%
array_dynamic_nested_blackbox_input_inliner_max 858 (-7) -0.81%
conditional_regression_short_circuit_inliner_zero 814 (-7) -0.85%
fold_call_witness_condition_inliner_max 114 (-1) -0.87%
fold_call_witness_condition_inliner_zero 114 (-1) -0.87%
regression_4449_inliner_zero 770 (-7) -0.90%
6_inliner_zero 731 (-7) -0.95%
regression_4449_inliner_max 727 (-7) -0.95%
inline_decompose_hint_brillig_call_inliner_min 274 (-3) -1.08%
integer_array_indexing_inliner_max 63 (-1) -1.56%
integer_array_indexing_inliner_min 63 (-1) -1.56%
integer_array_indexing_inliner_zero 63 (-1) -1.56%
global_var_regression_simple_inliner_min 236 (-4) -1.67%
global_var_regression_simple_inliner_max 132 (-4) -2.94%
global_var_regression_simple_inliner_zero 132 (-4) -2.94%
global_consts_inliner_min 316 (-28) -8.14%
global_consts_inliner_max 213 (-28) -11.62%
global_consts_inliner_zero 213 (-28) -11.62%
inline_decompose_hint_brillig_call_inliner_max 22 (-4) -15.38%
inline_decompose_hint_brillig_call_inliner_zero 22 (-4) -15.38%

Copy link
Contributor

github-actions bot commented Jan 15, 2025

Changes to number of Brillig opcodes executed

Generated at commit: 5b2bd32d506ff9c3366574ca5a1ecb7cec5a604e, compared to commit: 22cc6519ef47515bceeecbef45e5ae9b29dfbdf8

🧾 Summary (10% most significant diffs)

Program Brillig opcodes (+/-) %
fold_call_witness_condition_inliner_max -1 ✅ -1.43%
fold_call_witness_condition_inliner_zero -1 ✅ -1.43%
fold_call_witness_condition_inliner_min -1 ✅ -1.47%
global_consts_inliner_max -28 ✅ -1.68%
global_consts_inliner_zero -28 ✅ -1.68%
global_var_regression_simple_inliner_max -4 ✅ -2.37%
global_var_regression_simple_inliner_zero -4 ✅ -2.37%
inline_decompose_hint_brillig_call_inliner_max -4 ✅ -16.67%
inline_decompose_hint_brillig_call_inliner_zero -4 ✅ -16.67%

Full diff report 👇
Program Brillig opcodes (+/-) %
regression_4709_inliner_min 1,064,107 (-4) -0.00%
regression_4709_inliner_max 1,064,031 (-4) -0.00%
regression_4709_inliner_zero 1,064,031 (-4) -0.00%
ram_blowup_regression_inliner_min 822,247 (-4) -0.00%
ram_blowup_regression_inliner_zero 814,529 (-4) -0.00%
ram_blowup_regression_inliner_max 683,271 (-4) -0.00%
brillig_cow_regression_inliner_min 546,504 (-4) -0.00%
brillig_cow_regression_inliner_zero 540,488 (-4) -0.00%
brillig_cow_regression_inliner_max 454,771 (-5) -0.00%
u128_inliner_min 63,768 (-1) -0.00%
uhashmap_inliner_min 229,567 (-4) -0.00%
regression_4449_inliner_min 278,201 (-5) -0.00%
sha256_var_padding_regression_inliner_min 270,873 (-5) -0.00%
sha256_var_padding_regression_inliner_zero 265,640 (-5) -0.00%
u128_inliner_zero 44,332 (-1) -0.00%
uhashmap_inliner_zero 175,826 (-4) -0.00%
sha256_var_padding_regression_inliner_max 196,667 (-5) -0.00%
uhashmap_inliner_max 137,700 (-4) -0.00%
regression_4449_inliner_zero 227,255 (-7) -0.00%
sha256_regression_inliner_min 161,118 (-5) -0.00%
sha256_regression_inliner_zero 155,378 (-5) -0.00%
keccak256_inliner_max 30,622 (-1) -0.00%
hashmap_inliner_min 113,303 (-4) -0.00%
regression_4449_inliner_max 191,833 (-7) -0.00%
u128_inliner_max 24,276 (-1) -0.00%
sha2_byte_inliner_min 112,408 (-5) -0.00%
sha256_regression_inliner_max 111,509 (-5) -0.00%
hashmap_inliner_zero 75,732 (-4) -0.01%
hashmap_inliner_max 48,590 (-4) -0.01%
sha2_byte_inliner_zero 72,375 (-7) -0.01%
sha2_byte_inliner_max 44,560 (-7) -0.02%
sha256_brillig_performance_regression_inliner_min 27,143 (-5) -0.02%
sha256_brillig_performance_regression_inliner_zero 26,434 (-5) -0.02%
sha256_var_size_regression_inliner_min 23,371 (-5) -0.02%
array_dynamic_blackbox_input_inliner_min 23,108 (-5) -0.02%
sha256_var_size_regression_inliner_zero 21,398 (-5) -0.02%
array_dynamic_blackbox_input_inliner_zero 21,271 (-5) -0.02%
regression_inliner_min 3,935 (-1) -0.03%
sha256_inliner_min 18,486 (-5) -0.03%
sha256_brillig_performance_regression_inliner_max 21,958 (-6) -0.03%
array_dynamic_blackbox_input_inliner_max 17,476 (-5) -0.03%
sha256_var_size_regression_inliner_max 15,508 (-5) -0.03%
sha256_inliner_zero 15,315 (-5) -0.03%
regression_inliner_zero 2,714 (-1) -0.04%
regression_inliner_max 2,668 (-1) -0.04%
sha256_inliner_max 13,197 (-5) -0.04%
conditional_regression_short_circuit_inliner_min 9,501 (-5) -0.05%
6_inliner_min 9,395 (-5) -0.05%
ecdsa_secp256k1_inliner_min 8,804 (-5) -0.06%
sha256_var_witness_const_regression_inliner_min 8,505 (-5) -0.06%
sha256_var_witness_const_regression_inliner_zero 6,964 (-5) -0.07%
sha256_var_witness_const_regression_inliner_max 6,271 (-5) -0.08%
conditional_1_inliner_min 6,116 (-5) -0.08%
conditional_regression_short_circuit_inliner_zero 7,822 (-7) -0.09%
array_dynamic_nested_blackbox_input_inliner_min 5,560 (-5) -0.09%
6_inliner_zero 7,742 (-7) -0.09%
ecdsa_secp256k1_inliner_zero 7,613 (-7) -0.09%
strings_inliner_zero 2,100 (-2) -0.10%
conditional_regression_short_circuit_inliner_max 6,713 (-7) -0.10%
6_inliner_max 6,635 (-7) -0.11%
ecdsa_secp256k1_inliner_max 6,287 (-7) -0.11%
strings_inliner_max 1,730 (-2) -0.12%
conditional_1_inliner_zero 5,517 (-7) -0.13%
conditional_1_inliner_max 4,952 (-7) -0.14%
array_dynamic_nested_blackbox_input_inliner_zero 4,494 (-7) -0.16%
array_dynamic_nested_blackbox_input_inliner_max 4,108 (-7) -0.17%
inline_decompose_hint_brillig_call_inliner_min 313 (-3) -0.95%
global_var_regression_simple_inliner_min 338 (-4) -1.17%
global_consts_inliner_min 2,235 (-28) -1.24%
integer_array_indexing_inliner_max 77 (-1) -1.28%
integer_array_indexing_inliner_min 77 (-1) -1.28%
integer_array_indexing_inliner_zero 77 (-1) -1.28%
fold_call_witness_condition_inliner_max 69 (-1) -1.43%
fold_call_witness_condition_inliner_zero 69 (-1) -1.43%
fold_call_witness_condition_inliner_min 67 (-1) -1.47%
global_consts_inliner_max 1,641 (-28) -1.68%
global_consts_inliner_zero 1,641 (-28) -1.68%
global_var_regression_simple_inliner_max 165 (-4) -2.37%
global_var_regression_simple_inliner_zero 165 (-4) -2.37%
inline_decompose_hint_brillig_call_inliner_max 20 (-4) -16.67%
inline_decompose_hint_brillig_call_inliner_zero 20 (-4) -16.67%

@vezenovm vezenovm marked this pull request as ready for review January 15, 2025 21:05
@vezenovm vezenovm requested a review from a team January 15, 2025 21:05
Copy link
Contributor

github-actions bot commented Jan 15, 2025

Execution Report

Program Execution Time
sha256_regression 0.053s
regression_4709 0.001s
ram_blowup_regression 0.603s
rollup-root 0.104s
rollup-merge 0.007s
rollup-block-root 38.200s
rollup-block-merge 0.105s
rollup-base-public 1.224s
rollup-base-private 0.452s
private-kernel-tail 0.019s
private-kernel-reset 0.312s
private-kernel-inner 0.068s

Copy link
Contributor

github-actions bot commented Jan 15, 2025

Compilation Report

Program Compilation Time
sha256_regression 1.030s
regression_4709 0.799s
ram_blowup_regression 16.200s
rollup-root 3.678s
rollup-merge 2.164s
rollup-block-root-single-tx 147.000s
rollup-block-root-empty 2.030s
rollup-block-root 140.000s
rollup-block-merge 3.736s
rollup-base-public 28.600s
rollup-base-private 9.968s
private-kernel-tail 0.953s
private-kernel-reset 6.872s
private-kernel-inner 1.958s

Copy link
Contributor

github-actions bot commented Jan 15, 2025

Compilation Memory Report

Program Peak Memory %
keccak256 77.65M 0%
workspace 123.95M 0%
regression_4709 424.15M -17%
ram_blowup_regression 1.46G 0%
rollup-root 601.17M 0%
rollup-merge 494.01M 0%
rollup-block-root-single-tx 16.06G 0%
rollup-block-root-empty 488.18M 0%
rollup-block-root 16.07G 0%
rollup-block-merge 601.17M 0%
rollup-base-public 2.38G 0%
rollup-base-private 1.14G 0%
private-kernel-tail 207.26M 0%
private-kernel-reset 584.29M 0%
private-kernel-inner 294.48M 0%

Copy link
Contributor

github-actions bot commented Jan 15, 2025

Execution Memory Report

Program Peak Memory %
keccak256 74.71M 0%
workspace 123.95M 0%
regression_4709 316.02M -33%
ram_blowup_regression 512.62M 0%
rollup-root 498.48M 0%
rollup-merge 473.12M 0%
rollup-block-root 1.22G -94%
rollup-block-merge 498.50M 0%
rollup-base-public 733.93M 0%
rollup-base-private 590.59M 0%
private-kernel-tail 180.73M 0%
private-kernel-reset 245.33M 0%
private-kernel-inner 208.73M 0%

pub(crate) fn dead_instruction_elimination(
&mut self,
insert_out_of_bounds_checks: bool,
) -> HashSet<ValueId> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add some explanation to the docstrings about the new return value? Are the globals the only reasonable thing to return here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will add some comments. We do not need anything but the used globals as all other values are going to be per function.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a comment

@TomAFrench
Copy link
Member

Generally looks good to me, some nits. I think it's worth merging this into the other SSA globals PR due to the compilation speed regressions in there that are solved by this one

@vezenovm
Copy link
Contributor Author

vezenovm commented Jan 16, 2025

I think it's worth merging this into the other SSA globals PR due to the compilation speed regressions in there that are solved by this one

Yeah agreed. I will wait for all comments to be resolved before merging into #7021

@TomAFrench TomAFrench merged commit fe7f8b6 into mv/ssa-globals-brillig-gen Jan 16, 2025
97 checks passed
@TomAFrench TomAFrench deleted the mv/globals-die branch January 16, 2025 21:41
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.

3 participants