lang: Make idl build time way faster by caching CrateContext#4325
Open
cryptopapi997 wants to merge 7 commits intosolana-foundation:masterfrom
Open
lang: Make idl build time way faster by caching CrateContext#4325cryptopapi997 wants to merge 7 commits intosolana-foundation:masterfrom
CrateContext#4325cryptopapi997 wants to merge 7 commits intosolana-foundation:masterfrom
Conversation
|
@cryptopapi997 is attempting to deploy a commit to the Solana Foundation Team on Vercel. A member of the Team first needs to authorize it. |
CrateContextCrateContext
jamie-osec
reviewed
Mar 23, 2026
cryptopapi997
commented
Mar 24, 2026
Collaborator
|
Looks like there's errors around |
Contributor
Author
|
crap, sorry. Fixed now. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
CrateContext::parseparses the entire crate. It gets called for every user-defined type field. This effectively means if we have a large project, each call toCrateContext::parsetakes longer AND we're callingCrateContext::parsemore often, meaning it compounds in n^2. A simple fix to this is to simply cache the result ofCrateContext::parseonce, since the crate isn't changing while we're generating the idl.As to the impact of this: I came across this because I was helping out a friend whose project took ~20 min to incrementally build the idl (
anchor build --no-idltook ~1 min for comparison) each time due to this, with the change from this branch it takes ~30 sec instead. The repo is closed source so I can't link it, but I created a simple sample repo to showcase this issue at a smaller scale here. On my machine I get an approximate 10x improvement for incremental builds:Current main:
My branch: