-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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: Add Option to move init constraint codegen into separate functions #2920
Comments
Yeah, reducing stack usage is one of the top priorities now. Always creating a separate functions might even be better for Anchor. If so, we wouldn't need to make this optional.
I don't think there is anything particular that blocks this feature request. However, as with any performance issue, the problem must be identified and benchmarked properly first, rather than just making the codegen changes. |
how would that process looks like, care to point an example of this previously done i can follow , as the first part of it is done right ? its identified, what would an acceptable benchmark look like for the above issue ? as far as i understand its not possible to debug stack usage (i am not sure on this) if so how would a benchmark work ? |
It's not an exact science, but something like the following would help:
This could be done in |
@acheroncrypto reviewing the output code and the anchor lang internal generation code for constrains, it seems the code output is wrapped in a seperate scope by being wrapped in a scope({... init code}) if so shdnt this already alleviate stack space size issues since once the scope ends the stack space allocated within that scope is returned ?
basically the same thing from a stack size p.o.v, after the scope closes everything inside is dropped and deallocated(unless am wrong here)?
Produces -> (only dummy_a code shown)
|
@acheroncrypto it would be really easy to figure this out via experimentations if there is a way to measure stack space usage , i dont seem to know if there is any, would you happen to know of any ? if so it should help a ton in this specific scenario. |
was curious about the semantics around rust behavior of re-using of stack space, the conclusion i reached its not deterministic and sometimes might occur in some situation and might not , see here but solution is just to use modify the codegen to generate internal functions at compile time and use them to ensure a fresh solana stack frame is used. |
Allocating an array that blows the stack usually results in a build error: anchor/tests/bench/tests/stack-memory.ts Lines 13 to 14 in c96846f
It logs something like this:
That example is for the instruction handler function of Anchor, but you can also do it with constraints. However, if this doesn't work, and you'd need to check the binary itself to see what's going on, which is not the best experience to say the least:
Yeah, I think it's very difficult to tell if the compiler optimizes memory related stuff or not. Only reliable way I can think of is to analyze the generated bytecode. |
hey @acheroncrypto as discussed in the thread #2939 , its possible to guarantee |
Resolved by #2939 |
Problem :
As described in #2915 , Init constraints take up a lot of stack space, a medium number of them inside a single derive accounts would cause stack violated errors, the solution is to use composite structs but the issue is it leads to account duplication, Is there anything in particular that blocks the above feature request ? if not I would like to contribute this feature or atleast make it optional for people who need it , can use it.
The text was updated successfully, but these errors were encountered: