Skip to content

Compiler perf: track package alias environments in Salsa (1,167 rebuilds → ~10)#3913

Open
hellovai wants to merge 1 commit into
hellovai/compiler-perfo-alias-envfrom
hellovai/compiler-perfo-pkg-alias-query
Open

Compiler perf: track package alias environments in Salsa (1,167 rebuilds → ~10)#3913
hellovai wants to merge 1 commit into
hellovai/compiler-perfo-alias-envfrom
hellovai/compiler-perfo-pkg-alias-query

Conversation

@hellovai

@hellovai hellovai commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Third PR in the compiler-perf series, stacked on #3912 (which stacks on #3911).

The problem, measured by execution counts

Instrumenting one cold compile of the empty project (which compiles the stdlib) showed the type-alias environment being rebuilt 1,167 times:

Site Rebuilds What it did each time
infer_scope_types 1,053 (once per scope) collect own aliases + dep interface exports, clone every alias Ty, hand the builder an owned copy
callable_throws 708 (once per callable, overlapping the above) same map build + recursive-set derivation
resolved_aliases_for_package (MIR) ~2× per package collect aliases of the package and every dependency

The change

Two tracked queries, one per environment semantics (they are intentionally distinct and documented as such):

  • tir::inference::package_alias_env(db, pkg_id): own aliases + dependency interface exports (the TIR view). infer_scope_types, callable_throws, and the LSP check pass fetch it; TypeInferenceBuilder now borrows &'db ResolvedAliases instead of owning a per-scope copy.
  • mir::resolved_aliases_for_package(db, pkg_id), now #[salsa::tracked(returns(ref))]: all dependency aliases (the erasure view MIR/emit need). Emit's per-package caches hold &'db refs; package_lowering_data clones once per package.

After: ~10 environment builds per compile. Also deletes the LSP's now-redundant collect_type_aliases_for_resolution_context helper. Net −71/+79 lines.

Numbers (and a measurement caveat)

Measured back-to-back on battery power: 392ms → 363ms median (−7.5%).

The caveat worth recording: our earlier numbers in this series (1.41s → 281ms) were measured on AC power; battery throttling costs ~40% uniformly on this machine and initially masqueraded as a regression of this very change. The −7.5% above is a clean same-power-state A/B. AC-equivalent projection: ~260ms. AC re-measurement to follow.

Beyond wall time, this removes an allocation pattern that scales with project size (one full alias-map clone per scope), and moves the builder to the same borrow-from-Salsa discipline as the rest of the pipeline.

Validation

  • tir/mir/emit/lsp2_actions unit suites: 337 tests green
  • workspace cargo clippy --all-targets --all-features -- -D warnings: clean
  • full integration suite: CI

🤖 Generated with Claude Code

…compile)

The type-alias environment was rebuilt from scratch at three kinds of
sites, none of them memoized:

- infer_scope_types rebuilt the package alias map (own aliases plus
  dependency interface exports) and its recursive-alias set once PER
  SCOPE (1,053 times compiling the empty project's stdlib)
- callable_throws did the same once per analyzed callable (708 times)
- MIR's resolved_aliases_for_package recomputed per caller (emit's
  build_alias_caches and package_lowering_data)

Each rebuild re-collected every alias definition and cloned every alias
Ty. Now there are two tracked queries, one per environment semantics:

- tir::inference::package_alias_env(db, pkg_id): own aliases plus
  dependency *interface exports* -- the TIR view. infer_scope_types,
  callable_throws, and the LSP check pass fetch it; TypeInferenceBuilder
  borrows &'db ResolvedAliases instead of owning a per-scope copy.
- mir::resolved_aliases_for_package(db, pkg_id), now
  #[salsa::tracked(returns(ref))]: ALL dependency aliases -- the
  erasure view MIR/emit need. emit's alias caches hold &'db refs;
  package_lowering_data clones once per package.

Execution counts per empty-project compile: 1,167 environment builds
before, ~10 after. Empty-project cold compile measured back-to-back on
battery power: 392ms -> 363ms median (-7.5%); AC numbers to be
reconfirmed (the earlier 281ms baseline was measured on AC power).

Also deletes the LSP's collect_type_aliases_for_resolution_context
helper (now subsumed by the query).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@cursor

cursor Bot commented Jul 4, 2026

Copy link
Copy Markdown

Bugbot is not enabled for your account, so this pull request was not reviewed.

Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs.

@vercel

vercel Bot commented Jul 4, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
beps Ready Ready Preview, Comment Jul 4, 2026 2:27am
promptfiddle Ready Ready Preview, Comment Jul 4, 2026 2:27am
promptfiddle2 Ready Ready Preview, Comment Jul 4, 2026 2:27am

Request Review

@coderabbitai

coderabbitai Bot commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 788309b6-b22c-47d1-a7d6-1ae46e7aa216

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch hellovai/compiler-perfo-pkg-alias-query

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Jul 4, 2026

Copy link
Copy Markdown

⏭️ Performance benchmarks were skipped

Perf benchmarks (CodSpeed) are opt-in on pull requests — they no longer run on every push. They always run automatically after merge to canary/main.

To run them on this PR, do any of the following, then push a commit (or re-run CI):

  • Add RUN_CODSPEED=1 to the PR description, or
  • Include run-perf or /perf in the PR title or any commit message.

@github-actions

github-actions Bot commented Jul 4, 2026

Copy link
Copy Markdown

Binary size checks passed

7 passed

Artifact Platform File Gzip Gated on Baseline Delta Status
baml-cli Linux 🔒 21.6 MB 9.2 MB file 21.5 MB +98.1 KB (+0.5%) OK
packed-program Linux 🔒 15.8 MB 6.6 MB file 15.6 MB +148.6 KB (+1.0%) OK
baml-cli macOS 🔒 16.6 MB 8.0 MB file 16.6 MB +83.0 KB (+0.5%) OK
packed-program macOS 🔒 12.2 MB 5.8 MB file 12.1 MB +132.8 KB (+1.1%) OK
baml-cli Windows 🔒 18.2 MB 8.2 MB file 18.1 MB +79.9 KB (+0.4%) OK
packed-program Windows 🔒 13.1 MB 5.9 MB file 13.0 MB +116.3 KB (+0.9%) OK
bridge_wasm WASM 14.5 MB 🔒 4.1 MB gzip 4.1 MB +56.1 KB (+1.4%) OK

🔒 = the size this artifact is GATED on (ceiling + delta). Binaries gate on file size (installed binary); WASM gates on gzip (download size). The other size is shown for information only.


Generated by cargo size-gate · workflow run

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