Skip to content

feat(perf): Simplify array get when most recent array set writes to the same index#6220

Closed
vezenovm wants to merge 3 commits intomasterfrom
mv/expand-array-get-from-set-opt
Closed

feat(perf): Simplify array get when most recent array set writes to the same index#6220
vezenovm wants to merge 3 commits intomasterfrom
mv/expand-array-get-from-set-opt

Conversation

@vezenovm
Copy link
Contributor

@vezenovm vezenovm commented Oct 3, 2024

Description

Problem*

Part of general effort to reduce Brillig bytecode sizes

Summary*

This takes inspiration from #6207 that the value is still known at a previous array set when the index is dynamic.

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.

@github-actions
Copy link
Contributor

github-actions bot commented Oct 3, 2024

Changes to Brillig bytecode sizes

Generated at commit: 7cc3c5bf5b266e459a070fd49f5afe60cdc4b682, compared to commit: c3cb38a7c4de6fc321b367eda3fca6d06e76b77a

🧾 Summary (10% most significant diffs)

Program Brillig opcodes (+/-) %
slice_dynamic_index -28 ✅ -1.09%
nested_dyn_array_regression_5782 -10 ✅ -7.87%

Full diff report 👇
Program Brillig opcodes (+/-) %
slice_dynamic_index 2,547 (-28) -1.09%
nested_dyn_array_regression_5782 117 (-10) -7.87%

@github-actions
Copy link
Contributor

github-actions bot commented Oct 3, 2024

Changes to circuit sizes

Generated at commit: 7cc3c5bf5b266e459a070fd49f5afe60cdc4b682, compared to commit: c3cb38a7c4de6fc321b367eda3fca6d06e76b77a

🧾 Summary (10% most significant diffs)

Program ACIR opcodes (+/-) % Circuit size (+/-) %
regression_mem_op_predicate -6 ✅ -10.34% -11 ✅ -0.31%
slice_dynamic_index -18 ✅ -1.50% -35 ✅ -0.55%

Full diff report 👇
Program ACIR opcodes (+/-) % Circuit size (+/-) %
nested_dyn_array_regression_5782 30 (-2) -6.25% 2,832 (-5) -0.18%
regression_mem_op_predicate 52 (-6) -10.34% 3,552 (-11) -0.31%
slice_dynamic_index 1,182 (-18) -1.50% 6,384 (-35) -0.55%

@vezenovm vezenovm marked this pull request as ready for review October 3, 2024 19:23
@vezenovm vezenovm requested a review from a team October 3, 2024 19:27
Copy link
Member

@TomAFrench TomAFrench left a comment

Choose a reason for hiding this comment

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

I don't think this takes into account enable_side_effects. Can you add a test for this?

fn main(v1: [Field; 3], v2: u32) {
   enable_side_effects u1 0
   v4 = array_set v1, index v2, value v3
   enable_side_effects u1 1
   v5 = array_get v4, index v2
   return v5
}

@vezenovm
Copy link
Contributor Author

vezenovm commented Oct 4, 2024

I don't think this takes into account enable_side_effects

Ah yes good catch. I'm not sure if we can have this optimization here then as we need more information than just the array instructions. Going to convert this back to a draft for now.

@vezenovm vezenovm marked this pull request as draft October 4, 2024 15:34
@vezenovm
Copy link
Contributor Author

vezenovm commented Dec 2, 2024

Closing in as we need to do this during constant folding to take into account the predicate #6684

@vezenovm vezenovm closed this Dec 2, 2024
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