Skip to content

feat: optimize array reads from length 1 arrays#9203

Merged
TomAFrench merged 7 commits intomasterfrom
tf/optimize-length-one-array-reads
Jul 15, 2025
Merged

feat: optimize array reads from length 1 arrays#9203
TomAFrench merged 7 commits intomasterfrom
tf/optimize-length-one-array-reads

Conversation

@TomAFrench
Copy link
Member

Description

Problem*

Resolves

Summary*

This optimization deals with a couple of avoidable issues which arose in #9200. If we have a length 1 array then we can just optimistically read from index 0 and inject an assertion that the index will be zero.

This allows us to simplify some later instructions however the results are not shown against master due to #7827 currently injecting constraints which turn all of these array accesses into constant index accesses currently.

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.

@TomAFrench TomAFrench requested a review from a team July 14, 2025 20:36
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 'Execution Memory'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.20.

Benchmark suite Current: 09613b1 Previous: b331315 Ratio
rollup-base-private 714.77 MB 502.19 MB 1.42
rollup-base-public 601.01 MB 435.05 MB 1.38

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 'Test Suite Duration'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.20.

Benchmark suite Current: 971dc19 Previous: b331315 Ratio
test_report_AztecProtocol_aztec-packages_noir-projects_noir-protocol-circuits_crates_blob 235 s 170 s 1.38
test_report_zkpassport_noir_rsa_ 2 s 1 s 2

This comment was automatically generated by workflow using github-action-benchmark.

CC: @TomAFrench

@github-actions
Copy link
Contributor

Changes to number of Brillig opcodes executed

Generated at commit: 1881474aa85ad8cda61457fe37034fb6e0e05d75, compared to commit: b33131574388d836341cea9b6380f3b1a8493eb8

🧾 Summary (10% most significant diffs)

Program Brillig opcodes (+/-) %
lambda_from_array_inliner_max -73 ✅ -4.15%
lambda_from_array_inliner_min -73 ✅ -4.15%
lambda_from_array_inliner_zero -73 ✅ -4.15%

Full diff report 👇
Program Brillig opcodes (+/-) %
lambda_from_array_inliner_max 1,684 (-73) -4.15%
lambda_from_array_inliner_min 1,684 (-73) -4.15%
lambda_from_array_inliner_zero 1,684 (-73) -4.15%

@github-actions
Copy link
Contributor

Changes to Brillig bytecode sizes

Generated at commit: 1881474aa85ad8cda61457fe37034fb6e0e05d75, compared to commit: b33131574388d836341cea9b6380f3b1a8493eb8

🧾 Summary (10% most significant diffs)

Program Brillig opcodes (+/-) %
lambda_from_array_inliner_max -73 ✅ -2.85%
lambda_from_array_inliner_min -73 ✅ -2.85%
lambda_from_array_inliner_zero -73 ✅ -2.85%

Full diff report 👇
Program Brillig opcodes (+/-) %
lambda_from_array_inliner_max 2,484 (-73) -2.85%
lambda_from_array_inliner_min 2,484 (-73) -2.85%
lambda_from_array_inliner_zero 2,484 (-73) -2.85%

Copy link
Contributor

@guipublic guipublic left a comment

Choose a reason for hiding this comment

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

LGTM

@TomAFrench TomAFrench added this pull request to the merge queue Jul 15, 2025
Merged via the queue into master with commit e7a98f2 Jul 15, 2025
131 of 135 checks passed
@TomAFrench TomAFrench deleted the tf/optimize-length-one-array-reads branch July 15, 2025 14: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.

2 participants