Skip to content

Cache hot helpers recomputed during semantic analysis - #1617

Merged
sbillig merged 5 commits into
masterfrom
compiler-perf
Sep 28, 2026
Merged

sbillig merged 5 commits into
masterfrom
compiler-perf

Conversation

@sbillig

@sbillig sbillig commented Sep 28, 2026

Copy link
Copy Markdown
Collaborator

Profiling fe test over the fe_test fixtures showed most compile time in the semantic borrow checker and related queries, with large shares spent in helper functions that were recomputed on every call from inside those queries. This caches or shortcuts the biggest ones:

  • Body::containing_func finds the function from the body's parent scope instead of walking every item in the module (~7% of fe test time).
  • PredicateListId::extend_all_bounds is a salsa query keyed on the interned list (~12%). Normalizing implied bounds can lead back to the same list (trait projections, associated-type cycles), so it iterates to a fixpoint from the unextended list.
  • resolve_effect_handle is cached behind its cheap early-outs (~15%).
  • A function's input layout-hole bindings are cached for Func::arg_tys (~9%). Generic parameter collection still builds the implicit parameter plan directly, so the new query stays outside that cycle.
  • TyId::field_types is cached per type (~5% on a heavy fixture subset).

Local measurements (M-series, release):

  • fe test --jobs 1 over all fe_test fixtures: 254s -> ~140s.
  • Full nextest suite: total test time -28% (wall 228s -> 169s); corelib -50%, fmt round-trip -39%, cli_output -30%, semantic borrowck tests -22%.

A temporary assertion comparing the new containing_func lookup with the old module walk held across the full test suite. The full suite passes; snapshots are unchanged.

`Body::containing_func` walked every item in the module's scope graph to
find the function owning the body. A function body is lowered inside the
function's item scope, so the function is the body's lexical parent.

The walk took ~7% of `fe test` time over the fe_test fixtures, mostly via
`TypedBody::return_provenance`. A temporary assertion comparing both
lookups held across the full test suite.
`PredicateListId::extend_all_bounds` recomputed the transitive super-trait
and associated-type bounds on every trait selection and satisfiability
check, ~12% of `fe test` time over the fe_test fixtures. Make it a salsa
query keyed on the interned list.

Normalizing implied bounds can lead back to the same list (e.g. trait
projections and associated-type cycles in the ty_check/uitest fixtures),
so the query iterates to a fixpoint from the unextended list.
`resolve_effect_handle` ran trait impl selection for `EffectHandle` every
time the borrow checker or layout lowering asked whether a type is an
effect handle, ~15% of `fe test` time over the fe_test fixtures. Keep the
cheap rejections inline and cache the rest as a salsa query.
`Func::arg_tys` recomputed the full implicit parameter plan on every call
to find the bindings from input layout holes to implicit const params,
~9% of `fe test` time over the fe_test fixtures. Cache the bindings per
function. Generic parameter collection still builds the plan directly, so
the new query stays outside its cycle recovery.
`TyId::field_types` re-instantiated ADT field shapes on every call; the
borrow checker's shape building and `is_zero_sized` ask for the same
aggregates repeatedly. Cache the result per type (~5% of `fe test` time
over a heavy fe_test fixture subset).
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-28T16:29:55.971116Z 87a0053 PR opened
🔒 Security Review ✅ Completed 2026-09-28T16:46:10.348098Z 87a0053 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@sbillig
sbillig merged commit 7e33328 into master Sep 28, 2026
9 checks passed
@sbillig
sbillig deleted the compiler-perf branch September 28, 2026 17:45
cburgdorf added a commit that referenced this pull request Sep 30, 2026
Several user-facing changes merged after 26.3 were missing release notes
entries:

- Bugfixes: event ABI `anonymous` flag (#1562), string literal escapes
  (#1563), effect provider identity (#1564), shared calls on non-Copy
  fields (#1581), recursive raw pointer types (#1609).
- Performance: `DynArray::get` for static elements (#1559), constant
  string ABI encoding (#1560), compile-time caching (#1617, #1619, #1621).
- Native backend features: workspaces, native tests and `std::io`
  (#1565), process arguments and CPU timing (#1566), `ByteBuffer`
  (#1580).
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.

1 participant