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

fix(performance): Remove redundant slice access check from brillig #7434

Merged
merged 3 commits into from
Feb 18, 2025

Conversation

vezenovm
Copy link
Contributor

@vezenovm vezenovm commented Feb 18, 2025

Description

Problem*

No issue, small optimization I found while exploring other Brillig gen optimizations.

Summary*

For every slice access, we code gen a slice access check against its dynamic index:

self.codegen_slice_access_check(index, length);

In Brillig gen we use !dfg.is_safe_index to determine whether to code gen an array index. This always returns false for slice types as we cannot check against their length. However, we already have generated a check the precedes the array access. We should generate this validation code for array types in Brillig gen.

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 Feb 18, 2025

Changes to Brillig bytecode sizes

Generated at commit: 6052552d0f89b9cbbc3d8ad8dc365dadac3284f2, compared to commit: 988adae231c1aca09fd4d08d5e7bf5e72deecf9d

🧾 Summary (10% most significant diffs)

Program Brillig opcodes (+/-) %
slice_dynamic_index_inliner_min -450 ✅ -16.74%
slice_dynamic_index_inliner_max -450 ✅ -18.00%
slice_dynamic_index_inliner_zero -450 ✅ -18.00%
nested_array_in_slice_inliner_min -195 ✅ -19.21%
nested_array_in_slice_inliner_zero -195 ✅ -19.21%

Full diff report 👇
Program Brillig opcodes (+/-) %
hashmap_inliner_min 9,209 (-5) -0.05%
hashmap_inliner_zero 7,529 (-5) -0.07%
slice_coercion_inliner_min 478 (-8) -1.65%
modulus_inliner_min 1,731 (-30) -1.70%
modulus_inliner_max 1,716 (-30) -1.72%
modulus_inliner_zero 1,716 (-30) -1.72%
slice_loop_inliner_max 247 (-5) -1.98%
derive_inliner_min 559 (-13) -2.27%
hash_to_field_inliner_min 208 (-5) -2.35%
hint_black_box_inliner_min 364 (-10) -2.67%
hint_black_box_inliner_zero 354 (-10) -2.75%
slice_loop_inliner_min 317 (-10) -3.06%
slice_loop_inliner_zero 307 (-10) -3.15%
derive_inliner_zero 316 (-13) -3.95%
regression_4202_inliner_max 113 (-5) -4.24%
regression_4202_inliner_min 113 (-5) -4.24%
regression_4202_inliner_zero 113 (-5) -4.24%
hint_black_box_inliner_max 314 (-15) -4.56%
uhashmap_inliner_min 7,388 (-440) -5.62%
uhashmap_inliner_zero 6,762 (-425) -5.91%
array_to_slice_inliner_min 911 (-70) -7.14%
slices_inliner_max 1,979 (-153) -7.18%
slices_inliner_min 2,234 (-178) -7.38%
slices_inliner_zero 1,907 (-163) -7.87%
uhashmap_inliner_max 11,490 (-1,160) -9.17%
array_to_slice_inliner_zero 674 (-70) -9.41%
regression_capacity_tracker_inliner_max 216 (-23) -9.62%
regression_capacity_tracker_inliner_min 216 (-23) -9.62%
regression_capacity_tracker_inliner_zero 216 (-23) -9.62%
array_to_slice_inliner_max 627 (-75) -10.68%
nested_array_in_slice_inliner_max 850 (-155) -15.42%
regression_7062_inliner_max 91 (-18) -16.51%
regression_7062_inliner_min 91 (-18) -16.51%
regression_7062_inliner_zero 91 (-18) -16.51%
slice_dynamic_index_inliner_min 2,238 (-450) -16.74%
slice_dynamic_index_inliner_max 2,050 (-450) -18.00%
slice_dynamic_index_inliner_zero 2,050 (-450) -18.00%
nested_array_in_slice_inliner_min 820 (-195) -19.21%
nested_array_in_slice_inliner_zero 820 (-195) -19.21%

Copy link
Contributor

github-actions bot commented Feb 18, 2025

Changes to number of Brillig opcodes executed

Generated at commit: 6052552d0f89b9cbbc3d8ad8dc365dadac3284f2, compared to commit: 988adae231c1aca09fd4d08d5e7bf5e72deecf9d

🧾 Summary (10% most significant diffs)

Program Brillig opcodes (+/-) %
modulus_inliner_max -2,544 ✅ -14.16%
modulus_inliner_zero -2,544 ✅ -14.16%
regression_7062_inliner_max -12 ✅ -15.19%
regression_7062_inliner_min -12 ✅ -15.19%
regression_7062_inliner_zero -12 ✅ -15.19%

Full diff report 👇
Program Brillig opcodes (+/-) %
hashmap_inliner_min 86,962 (-316) -0.36%
hash_to_field_inliner_min 932 (-4) -0.43%
hashmap_inliner_zero 72,465 (-316) -0.43%
slice_coercion_inliner_min 465 (-4) -0.85%
regression_capacity_tracker_inliner_max 901 (-12) -1.31%
regression_capacity_tracker_inliner_min 901 (-12) -1.31%
regression_capacity_tracker_inliner_zero 901 (-12) -1.31%
slice_loop_inliner_max 869 (-32) -3.55%
uhashmap_inliner_min 183,030 (-8,196) -4.29%
slices_inliner_max 3,124 (-152) -4.64%
uhashmap_inliner_zero 163,387 (-8,036) -4.69%
slice_loop_inliner_min 1,211 (-64) -5.02%
slice_loop_inliner_zero 1,197 (-64) -5.08%
slices_inliner_min 3,947 (-212) -5.10%
uhashmap_inliner_max 128,594 (-7,184) -5.29%
slices_inliner_zero 3,379 (-192) -5.38%
hint_black_box_inliner_min 942 (-60) -5.99%
slice_dynamic_index_inliner_min 4,591 (-296) -6.06%
hint_black_box_inliner_zero 928 (-60) -6.07%
array_to_slice_inliner_max 1,537 (-100) -6.11%
slice_dynamic_index_inliner_max 4,360 (-296) -6.36%
slice_dynamic_index_inliner_zero 4,360 (-296) -6.36%
array_to_slice_inliner_min 2,061 (-148) -6.70%
nested_array_in_slice_inliner_max 1,265 (-92) -6.78%
nested_array_in_slice_inliner_min 1,584 (-128) -7.48%
nested_array_in_slice_inliner_zero 1,584 (-128) -7.48%
array_to_slice_inliner_zero 1,796 (-148) -7.61%
regression_4202_inliner_max 189 (-16) -7.80%
regression_4202_inliner_min 189 (-16) -7.80%
regression_4202_inliner_zero 189 (-16) -7.80%
hint_black_box_inliner_max 615 (-60) -8.89%
modulus_inliner_min 15,472 (-2,544) -14.12%
modulus_inliner_max 15,422 (-2,544) -14.16%
modulus_inliner_zero 15,422 (-2,544) -14.16%
regression_7062_inliner_max 67 (-12) -15.19%
regression_7062_inliner_min 67 (-12) -15.19%
regression_7062_inliner_zero 67 (-12) -15.19%

@vezenovm vezenovm requested review from sirasistant and a team February 18, 2025 23:15
@TomAFrench
Copy link
Member

TomAFrench commented Feb 18, 2025

Actually, looks like we could match on array_variable inside of validate_array_index and early return on vectors to encapsulate the check. ignore this

@vezenovm vezenovm added this pull request to the merge queue Feb 18, 2025
Merged via the queue into master with commit 49a095d Feb 18, 2025
102 checks passed
@vezenovm vezenovm deleted the mv/avoid-redundant-slice-access-check branch February 18, 2025 23:53
TomAFrench added a commit that referenced this pull request Feb 19, 2025
* master:
  fix(performance): Remove redundant slice access check from brillig (#7434)
  chore(docs): updating tutorials and other nits to beta.2 (#7405)
  feat: LSP hover for integer literals (#7368)
  feat(experimental): Compile match expressions (#7312)
  feat(acir_field): Add little-endian byte serialization for FieldElement (#7258)
  feat: allow unquoting TraitConstraint in trait impl position (#7395)
  feat(brillig): Hoist shared constants across functions to the global space (#7216)
  feat(LSP): auto-import via visible reexport (#7409)
  fix(brillig): Brillig entry point analysis and function specialization through duplication (#7277)
  chore: redo typo PR by maximevtush (#7425)
  fix(ssa): Accurately mark binary ops for hoisting and check Div/Mod against induction variable lower bound (#7396)
  feat!: remove bigint from stdlib (#7411)
AztecBot added a commit to AztecProtocol/aztec-packages that referenced this pull request Feb 19, 2025
…m brillig (noir-lang/noir#7434)

chore(docs): updating tutorials and other nits to beta.2 (noir-lang/noir#7405)
feat: LSP hover for integer literals (noir-lang/noir#7368)
feat(experimental): Compile match expressions (noir-lang/noir#7312)
feat(acir_field): Add little-endian byte serialization for FieldElement (noir-lang/noir#7258)
feat: allow unquoting TraitConstraint in trait impl position (noir-lang/noir#7395)
feat(brillig): Hoist shared constants across functions to the global space (noir-lang/noir#7216)
feat(LSP): auto-import via visible reexport (noir-lang/noir#7409)
fix(brillig): Brillig entry point analysis and function specialization through duplication (noir-lang/noir#7277)
chore: redo typo PR by maximevtush (noir-lang/noir#7425)
fix(ssa): Accurately mark binary ops for hoisting and check Div/Mod against induction variable lower bound (noir-lang/noir#7396)
feat!: remove bigint from stdlib (noir-lang/noir#7411)
chore: bump aztec-packages commit (noir-lang/noir#7415)
chore: deprecate `merkle` module of stdlib (noir-lang/noir#7413)
chore(ci): lock aztec-packages commit in CI (noir-lang/noir#7414)
feat: while statement (noir-lang/noir#7280)
AztecBot added a commit to AztecProtocol/aztec-packages that referenced this pull request Feb 19, 2025
…oir-lang/noir#7434)

chore(docs): updating tutorials and other nits to beta.2 (noir-lang/noir#7405)
feat: LSP hover for integer literals (noir-lang/noir#7368)
feat(experimental): Compile match expressions (noir-lang/noir#7312)
feat(acir_field): Add little-endian byte serialization for FieldElement (noir-lang/noir#7258)
feat: allow unquoting TraitConstraint in trait impl position (noir-lang/noir#7395)
feat(brillig): Hoist shared constants across functions to the global space (noir-lang/noir#7216)
feat(LSP): auto-import via visible reexport (noir-lang/noir#7409)
fix(brillig): Brillig entry point analysis and function specialization through duplication (noir-lang/noir#7277)
chore: redo typo PR by maximevtush (noir-lang/noir#7425)
fix(ssa): Accurately mark binary ops for hoisting and check Div/Mod against induction variable lower bound (noir-lang/noir#7396)
feat!: remove bigint from stdlib (noir-lang/noir#7411)
chore: bump aztec-packages commit (noir-lang/noir#7415)
chore: deprecate `merkle` module of stdlib (noir-lang/noir#7413)
chore(ci): lock aztec-packages commit in CI (noir-lang/noir#7414)
feat: while statement (noir-lang/noir#7280)
TomAFrench added a commit to AztecProtocol/aztec-packages that referenced this pull request Feb 19, 2025
Automated pull of development from the
[noir](https://github.com/noir-lang/noir) programming language, a
dependency of Aztec.
BEGIN_COMMIT_OVERRIDE
fix(performance): Remove redundant slice access check from brillig
(noir-lang/noir#7434)
chore(docs): updating tutorials and other nits to beta.2
(noir-lang/noir#7405)
feat: LSP hover for integer literals
(noir-lang/noir#7368)
feat(experimental): Compile match expressions
(noir-lang/noir#7312)
feat(acir_field): Add little-endian byte serialization for FieldElement
(noir-lang/noir#7258)
feat: allow unquoting TraitConstraint in trait impl position
(noir-lang/noir#7395)
feat(brillig): Hoist shared constants across functions to the global
space (noir-lang/noir#7216)
feat(LSP): auto-import via visible reexport
(noir-lang/noir#7409)
fix(brillig): Brillig entry point analysis and function specialization
through duplication (noir-lang/noir#7277)
chore: redo typo PR by maximevtush
(noir-lang/noir#7425)
fix(ssa): Accurately mark binary ops for hoisting and check Div/Mod
against induction variable lower bound
(noir-lang/noir#7396)
feat!: remove bigint from stdlib
(noir-lang/noir#7411)
chore: bump aztec-packages commit
(noir-lang/noir#7415)
chore: deprecate `merkle` module of stdlib
(noir-lang/noir#7413)
chore(ci): lock aztec-packages commit in CI
(noir-lang/noir#7414)
feat: while statement (noir-lang/noir#7280)
END_COMMIT_OVERRIDE

---------

Co-authored-by: Tom French <tom@tomfren.ch>
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