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(optimization): Redirect array gets to earlier arrays if possible #5785

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

Conversation

jfecher
Copy link
Contributor

@jfecher jfecher commented Aug 21, 2024

Description

Problem*

Resolves comment #5772 (comment)

Summary*

This PR redirects array_gets to work on earlier arrays if they can (currently only block parameters.
This can potentially optimize code by allowing more array gets to be deduplicated but may also prevent optimizing array_sets to be mutable if older arrays are now being used more.

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.

Copy link
Contributor

github-actions bot commented Aug 21, 2024

Changes to Brillig bytecode sizes

Generated at commit: fe0010828b76c355b3ded81f304f601a2530995e, compared to commit: 8dec84793d200dcb524aa5c397d0a84d38974e7e

🧾 Summary (10% most significant diffs)

Program Brillig opcodes (+/-) %
brillig_arrays -41 ✅ -36.61%

Full diff report 👇
Program Brillig opcodes (+/-) %
brillig_arrays 71 (-41) -36.61%

Copy link
Contributor

github-actions bot commented Aug 21, 2024

Changes to circuit sizes

Generated at commit: fe0010828b76c355b3ded81f304f601a2530995e, compared to commit: 8dec84793d200dcb524aa5c397d0a84d38974e7e

🧾 Summary (10% most significant diffs)

Program ACIR opcodes (+/-) % Circuit size (+/-) %
conditional_1 -35 ✅ -0.76% -125 ✅ -0.97%
array_if_cond_simple -71 ✅ -63.96% -312 ✅ -9.96%

Full diff report 👇
Program ACIR opcodes (+/-) % Circuit size (+/-) %
conditional_1 4,590 (-35) -0.76% 12,725 (-125) -0.97%
array_if_cond_simple 40 (-71) -63.96% 2,822 (-312) -9.96%

@TomAFrench
Copy link
Member

Is this ready for review?

@jfecher
Copy link
Contributor Author

jfecher commented Aug 23, 2024

Maybe. I'm still not sure if this optimization is worth it. Since it'd only have an effect on small programs I think due to the constant limit of how many instructions it can look past to. It also may lead to worse performance if that block parameter had a array_set_mut to it previously but can't anymore since now more array gets to it are inserted.

@jfecher jfecher marked this pull request as ready for review August 23, 2024 13:26
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.

2 participants