-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Use closure for init constraints #2939
base: master
Are you sure you want to change the base?
Conversation
@CanardMandarin is attempting to deploy a commit to the coral-xyz Team on Vercel. A member of the Team first needs to authorize it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using closures for init constraints helps decrease the stack usage and helps mitigate the issue.
That's definitely interesting because using map_err
and creating a closure uses more stack space compared to regular match
statements. I'm also not sure if this behavior will always be the same with all Rust versions.
Is it possible to add a test that demonstrates the improvement in stack usage?
@acheroncrypto @CanardMandarin , are closures always guranteed to be |
so i tested it out with the following struct , reduced stack usage from 15k to 4k.
Got good results , |
hm? yeah you can. |
Hey
Seems i misread that pr and thought its still not avbl on stable-wrapping in curly braces compiles fine- thanks for the headsup @workingjubilee . |
Hello,
This PR is somewhat related to issues #2915 and #2920.
It seems that with Anchor 0.29, stack usage in
try_accounts
increased and more easily causesStack offset of X exceeded max offset of 4096 by X bytes, please minimize large stack variables
error.Existing projects using Anchor could have trouble migrating, and it looks like this question appears a lot in Discord.
Using closures for init constraints helps decrease the stack usage and helps mitigate the issue.
What do you think?