Skip to content

lang: Make idl build time way faster by caching CrateContext#4325

Open
cryptopapi997 wants to merge 7 commits intosolana-foundation:masterfrom
cryptopapi997:master
Open

lang: Make idl build time way faster by caching CrateContext#4325
cryptopapi997 wants to merge 7 commits intosolana-foundation:masterfrom
cryptopapi997:master

Conversation

@cryptopapi997
Copy link
Copy Markdown
Contributor

@cryptopapi997 cryptopapi997 commented Mar 18, 2026

CrateContext::parse parses the entire crate. It gets called for every user-defined type field. This effectively means if we have a large project, each call to CrateContext::parse takes longer AND we're calling CrateContext::parse more often, meaning it compounds in n^2. A simple fix to this is to simply cache the result of CrateContext::parse once, 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-idl took ~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:

$ cargo check --features idl-build
    Checking idl-build-perf v0.1.0
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 26.99s

My branch:

$ cargo check --features idl-build
    Checking idl-build-perf v0.1.0
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 2.51s

@vercel
Copy link
Copy Markdown

vercel bot commented Mar 18, 2026

@cryptopapi997 is attempting to deploy a commit to the Solana Foundation Team on Vercel.

A member of the Team first needs to authorize it.

@cryptopapi997 cryptopapi997 changed the title Make idl build time way faster by caching CrateContext lang: Make idl build time way faster by caching CrateContext Mar 18, 2026
@jamie-osec
Copy link
Copy Markdown
Collaborator

Looks like there's errors around anyhow

@cryptopapi997
Copy link
Copy Markdown
Contributor Author

crap, sorry. Fixed now.

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