(opt): memoize function code size estimation - #10348
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
PR SummaryLow Risk Overview Inlining and specialization heuristics were calling this heavily on overlapping function sets; each miss could run the configured estimator or the fallback path over post-baseline lowered IR. The PR documents that Reviewed by Cursor Bugbot for commit 4d43770. Bugbot is set up for automated code reviews on this repo. Configure here. |
d526b81 to
01aab53
Compare
eytan-starkware
left a comment
There was a problem hiding this comment.
@eytan-starkware+AGNT made 2 comments.
Reviewable status: 0 of 1 files reviewed, 1 unresolved discussion (waiting on eytan-starkware, orizi, and TomerStarkware).
a discussion (no related file):
Note: the comments below are from an automatic orizi-review run (Claude agents reviewing in Ori's style, findings adversarially verified before posting). Treat with the usual bot skepticism.
crates/cairo-lang-lowering/src/db.rs line 836 at r1 (raw file):
} #[salsa::tracked(returns(copy))]
caching this turns the code_size_estimator hook into a purity contract - it's a pub param of init_lowering_group, so an embedder supplying a non-deterministic estimator now silently gets stale results instead of just being slow. worth saying so on the field doc (line 50):
/// A configurable function to get estimated size of the function with the given id.
/// Must be a pure function of the db - results are memoized.
estimate_size was a plain function - each call built a dummy Sierra program and ran a full Sierra-to-casm compilation - and the inlining and specialization heuristics repeatedly request it for the same functions (measured: 9976 calls, 5878 distinct, single ids requested up to 700 times). In a full compilation of cairo_level_tests its subtree was 56% of all CPU, dwarfing the actual code emission. Now a tracked query. Improves full-compilation CPU by ~9%. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
01aab53 to
4d43770
Compare
orizi
left a comment
There was a problem hiding this comment.
@orizi+AGNT made 1 comment and resolved 1 discussion.
Reviewable status: 0 of 1 files reviewed, all discussions resolved (waiting on TomerStarkware).
crates/cairo-lang-lowering/src/db.rs line 836 at r1 (raw file):
Previously, eytan-starkware+AGNT (Agent AGNT for eytan-starkware) wrote…
caching this turns the
code_size_estimatorhook into a purity contract - it's apubparam ofinit_lowering_group, so an embedder supplying a non-deterministic estimator now silently gets stale results instead of just being slow. worth saying so on the field doc (line 50):/// A configurable function to get estimated size of the function with the given id. /// Must be a pure function of the db - results are memoized.
Done.

estimate_size was a plain function - each call built a dummy Sierra
program and ran a full Sierra-to-casm compilation - and the inlining and
specialization heuristics repeatedly request it for the same functions
(measured: 9976 calls, 5878 distinct, single ids requested up to 700
times). In a full compilation of cairo_level_tests its subtree was 56%
of all CPU, dwarfing the actual code emission. Now a tracked query.
Improves full-compilation CPU by ~9%.
Co-Authored-By: Claude Fable 5 noreply@anthropic.com