-
Notifications
You must be signed in to change notification settings - Fork 225
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
Local array indexed dynamic is re-initialized unnecessarily #5529
Comments
To further back this up this is the SSA and printed
For the struct version the SSA is essentially identical (with only the exact value IDs differing). Here is the printed [compiler/noirc_evaluator/src/ssa/acir_gen/mod.rs:434] self.memory_blocks.clone() = {
Id(
0,
): BlockId(
0,
),
Id(
65,
): BlockId(
1,
),
Id(
269,
): BlockId(
2,
),
}
[compiler/noirc_evaluator/src/ssa/acir_gen/mod.rs:435] self.memory_blocks.len() = 3 It looks as though we have |
Looks to be a repeat issue of (#5286) but for this case we still have the duplication. |
# Description ## Problem\* Resolves #5529 ## Summary\* In #5287 we added a check to avoid duplication of arrays. However, we can make this check more complete by allowing us to check constant arrays based off of their contents when we are inside of ACIR and also distinguishing between arrays and slices. The program in the issue, for any size input array, is now the same number of ACIR gates for both versions (using a local array variable and an array fetched from a function). ## Additional Context ## Documentation\* Check one: - [X] No documentation needed. - [ ] Documentation included in this PR. - [ ] **[For Experimental Features]** Documentation to be submitted in a separate PR. # PR Checklist\* - [X] I have tested the changes locally. - [X] I have formatted the changes with [Prettier](https://prettier.io/) and/or `cargo fmt` on default settings.
Aim
In this base64 repo @zac-williamson noticed a blow-up when the same array as a local variable vs. when it was returned from a function.
A smaller reproduction can be found here:
Expected Behavior
As the size of the
x
input to main is increased the acir count of usingbase64_decode_without_struct
andbase64_decode_with_struct
should stay the same.Bug
Even with
x.len() == 2
we have one extra gate forbase64_decode_without_struct
. This continues to increase as we increase the size of thex
array.The size of the
x
array does determine how many loop iterations we perform, where in each iteration we are reading from the provided constant array. The gate increase between the two versions looks to always bex.len() - 1
. In fact, when looking at the final ACIR it looks like we havex.len() - 1
more memoryINIT
operations in the local variable array version. So it looks to me like we are reinitializing the local array for each loop iteration when it can actually be re-used.To Reproduce
nargo info
base64_decode_with_struct
and compare the acir countsx
input to main to see the blow-up increase with the input.Project Impact
Nice-to-have
Impact Context
This isn't blocking but forces people to work around the blow-up.
Workaround
Yes
Workaround Description
The work around is provided in the main description of the bug.
Additional Context
No response
Installation Method
None
Nargo Version
No response
NoirJS Version
No response
Would you like to submit a PR for this Issue?
None
Support Needs
No response
The text was updated successfully, but these errors were encountered: