Skip to content

perf: store per-module constant prefix trees in oleans#14362

Draft
Kha wants to merge 15 commits into
masterfrom
olean-const-trie
Draft

perf: store per-module constant prefix trees in oleans#14362
Kha wants to merge 15 commits into
masterfrom
olean-const-trie

Conversation

@Kha

@Kha Kha commented Jul 11, 2026

Copy link
Copy Markdown
Member

This PR replaces the eager construction of the imported-constants hash maps in finalizeImport (privateConstantMap, publicConstantMap, const2ModIdx; ~530k insertions for import Lean) with prefix trees over each module's constant names that are precomputed at olean write time and remain in the memory-mapped compacted regions. Import now only merges the per-module trees, allocating fresh nodes solely for name prefixes shared between modules (~3k nodes / ~81k edges for the stdlib), and lookups walk the merged view, disambiguating children by cached per-prefix Name hash. import Lean drops from ~527ms to ~393ms; olean sizes grow by ~6%.

Details:

  • New Lean.ConstTrie: generic per-module tree (ConstTrie α), merged import view (ImportedConsts α) with single-module subtrees borrowed from the regions and module-index tagging, and the new ConstMap structure (imported view + locals map).
  • ModuleData gains constTrie/extraConstTrie fields, filled centrally in saveModuleData(Parts). The extra-const tree replaces the 325k codegen-name entries of const2ModIdx (Kernel.Environment now holds allImportedConsts/importedExtraConsts instead, serving getModuleIdxFor?).
  • Duplicate imported constants are resolved (incl. subsumesInfo realizability subsumption and throwAlreadyImported) from the merge's reported collisions.
  • In saveModuleDataParts, all parts' data must stay alive across the chained compactor saves; the tries are therefore attached to all parts up front (the compactor tracks compacted objects by heap address, so per-part temporaries would corrupt later parts via address reuse).
  • stage0/src/stdlib_flags.h temporarily enables interpreter.prefer_native as this is an ABI-breaking change to Kernel.Environment/ConstMap (to be reverted by update-stage0). Stage 1 tests are meaningless on this commit since the stage 1 oleans lack the new ModuleData fields; validate against stage 2.

@Kha

Kha commented Jul 11, 2026

Copy link
Copy Markdown
Member Author

!bench

@leanprover-radar

leanprover-radar commented Jul 11, 2026

Copy link
Copy Markdown

Benchmark results for 7a68001 against 8006bb0 are in. There are significant results. @Kha

Warning

These warnings may indicate that the benchmark results are not directly comparable, for example due to changes in the runner configuration or hardware.

  • Bench repo commit hashes for run build differ between commits.
  • Bench repo commit hashes for run other differ between commits.
  • 🟥 build//instructions: +6.3T (+52.95%)

Large changes (55✅, 329🟥)

Too many entries to display here. View the full report on radar instead.

Medium changes (7✅, 1528🟥)

Too many entries to display here. View the full report on radar instead.

Small changes (5✅, 816🟥)

Too many entries to display here. View the full report on radar instead.

@github-actions github-actions Bot added toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN mathlib4-nightly-available A branch for this PR exists at leanprover-community/mathlib4-nightly-testing:lean-pr-testing-NNNN labels Jul 11, 2026
@leanprover-bot

leanprover-bot commented Jul 11, 2026

Copy link
Copy Markdown
Collaborator

Reference manual CI status:

@leanprover-bot leanprover-bot added the breaks-manual This is not necessarily a blocker for merging, but there needs to be a plan. label Jul 11, 2026
@Kha

Kha commented Jul 11, 2026

Copy link
Copy Markdown
Member Author

!bench mathlib

@leanprover-radar

leanprover-radar commented Jul 11, 2026

Copy link
Copy Markdown

Benchmark results for leanprover-community/mathlib4-nightly-testing@48fbe78 against leanprover-community/mathlib4-nightly-testing@5edfd4c are in. There are significant results. @Kha

  • 🟥 main exited with code 1

No significant changes detected.

@Kha Kha force-pushed the olean-const-trie branch from 7a68001 to 736e8af Compare July 11, 2026 14:03
@Kha

Kha commented Jul 11, 2026

Copy link
Copy Markdown
Member Author

!bench

@leanprover-radar

leanprover-radar commented Jul 11, 2026

Copy link
Copy Markdown

Benchmark results for 736e8af against 8006bb0 are in. There are significant results. @Kha

Warning

These warnings may indicate that the benchmark results are not directly comparable, for example due to changes in the runner configuration or hardware.

  • Bench repo commit hashes for run build differ between commits.
  • Bench repo commit hashes for run other differ between commits.
  • 🟥 build//instructions: +4.5T (+38.02%)

Large changes (56✅, 232🟥)

Too many entries to display here. View the full report on radar instead.

Medium changes (5✅, 1101🟥)

Too many entries to display here. View the full report on radar instead.

Small changes (6✅, 1324🟥)

Too many entries to display here. View the full report on radar instead.

Kha added 2 commits July 11, 2026 14:09
This PR replaces the eager construction of the imported-constants hash maps in `finalizeImport` (`privateConstantMap`, `publicConstantMap`, `const2ModIdx`; ~530k insertions for `import Lean`) with prefix trees over each module's constant names that are precomputed at olean write time and remain in the memory-mapped compacted regions. Import now only merges the per-module trees, allocating fresh nodes solely for name prefixes shared between modules (~3k nodes / ~81k edges for the stdlib), and lookups walk the merged view, disambiguating children by cached per-prefix `Name` hash. `import Lean` drops from ~527ms to ~393ms; olean sizes grow by ~6%.

Details:

* New `Lean.ConstTrie`: generic per-module tree (`ConstTrie α`), merged import view (`ImportedConsts α`) with single-module subtrees borrowed from the regions and module-index tagging, and the new `ConstMap` structure (`imported` view + `locals` map).
* `ModuleData` gains `constTrie`/`extraConstTrie` fields, filled centrally in `saveModuleData(Parts)`. The extra-const tree replaces the 325k codegen-name entries of `const2ModIdx` (`Kernel.Environment` now holds `allImportedConsts`/`importedExtraConsts` instead, serving `getModuleIdxFor?`).
* Duplicate imported constants are resolved (incl. `subsumesInfo` realizability subsumption and `throwAlreadyImported`) from the merge's reported collisions.
* In `saveModuleDataParts`, all parts' data must stay alive across the chained compactor saves; the tries are therefore attached to all parts up front (the compactor tracks compacted objects by heap address, so per-part temporaries would corrupt later parts via address reuse).
* `stage0/src/stdlib_flags.h` temporarily enables `interpreter.prefer_native` as this is an ABI-breaking change to `Kernel.Environment`/`ConstMap` (to be reverted by `update-stage0`). Stage 1 tests are meaningless on this commit since the stage 1 oleans lack the new `ModuleData` fields; validate against stage 2.

Co-Authored-By: Claude
This PR speeds up constant lookups in the prefix-tree-backed environment by storing each trie node's child key hashes in a `ByteArray` alongside the children, so the per-level binary search runs over contiguous memory instead of chasing child and key pointers, in the memory-mapped per-module trees as well as the merged import spine. This supersedes the `indexed` hash-map wrappers on wide merged nodes, which could not cover wide nodes inside single-module region subtrees and made `Runtime.markPersistent` walk their entries on every import.

Co-Authored-By: Claude
mathlib-nightly-testing Bot pushed a commit to leanprover-community/batteries that referenced this pull request Jul 11, 2026
mathlib-nightly-testing Bot pushed a commit to leanprover-community/mathlib4-nightly-testing that referenced this pull request Jul 11, 2026
leanprover-bot added a commit to leanprover/reference-manual that referenced this pull request Jul 11, 2026
@leanprover-bot leanprover-bot added builds-manual CI has verified that the Lean Language Reference builds against this PR and removed breaks-manual This is not necessarily a blocker for merging, but there needs to be a plan. labels Jul 11, 2026
@Kha Kha force-pushed the olean-const-trie branch from 736e8af to 2abb3e2 Compare July 11, 2026 15:26
@Kha

Kha commented Jul 11, 2026

Copy link
Copy Markdown
Member Author

!bench

@leanprover-radar

leanprover-radar commented Jul 11, 2026

Copy link
Copy Markdown

Benchmark results for 2abb3e2 against 8006bb0 are in. There are significant results. @Kha

Warning

These warnings may indicate that the benchmark results are not directly comparable, for example due to changes in the runner configuration or hardware.

  • Bench repo commit hashes for run build differ between commits.
  • Bench repo commit hashes for run other differ between commits.
  • 🟥 build//instructions: +8.2T (+69.20%)

Large changes (49✅, 433🟥)

Too many entries to display here. View the full report on radar instead.

Medium changes (9✅, 1889🟥)

Too many entries to display here. View the full report on radar instead.

Small changes (4✅, 369🟥)

Too many entries to display here. View the full report on radar instead.

mathlib-nightly-testing Bot pushed a commit to leanprover-community/batteries that referenced this pull request Jul 11, 2026
mathlib-nightly-testing Bot pushed a commit to leanprover-community/mathlib4-nightly-testing that referenced this pull request Jul 11, 2026
leanprover-bot added a commit to leanprover/reference-manual that referenced this pull request Jul 11, 2026
This PR restores the intended final form of the trie child index, which the previous commit accidentally carried in an interim form due to a workspace snapshot race: instead of a binary search that composes each probed hash from eight byte loads, the child index stores `[k][2^k + 1 u16 offsets][one fingerprint byte per child]`; the query hash's top `k` bits select a window of on average at most one child, a fingerprint byte filters it, and the final name component comparison (sound on its own, as siblings always differ in their final component) confirms the match.

Co-Authored-By: Claude
@Kha

Kha commented Jul 11, 2026

Copy link
Copy Markdown
Member Author

!bench

@leanprover-radar

leanprover-radar commented Jul 11, 2026

Copy link
Copy Markdown

Benchmark results for e957cab against 8006bb0 are in. There are significant results. @Kha

Warning

These warnings may indicate that the benchmark results are not directly comparable, for example due to changes in the runner configuration or hardware.

  • Bench repo commit hashes for run build differ between commits.
  • Bench repo commit hashes for run other differ between commits.
  • 🟥 build//instructions: +2.6T (+21.58%)

Large changes (52✅, 126🟥)

Too many entries to display here. View the full report on radar instead.

Medium changes (7✅, 560🟥)

Too many entries to display here. View the full report on radar instead.

Small changes (6✅, 1925🟥)

Too many entries to display here. View the full report on radar instead.

mathlib-nightly-testing Bot pushed a commit to leanprover-community/batteries that referenced this pull request Jul 11, 2026
mathlib-nightly-testing Bot pushed a commit to leanprover-community/mathlib4-nightly-testing that referenced this pull request Jul 11, 2026
leanprover-bot added a commit to leanprover/reference-manual that referenced this pull request Jul 11, 2026
The compat accessor recomputed the map by folding over all imported constants on every call. `Batteries.Tactic.Lint.getDeclsInPackage` reads it inside a per-declaration fold, turning linting into a quadratic walk over millions of constants on mathlib — `lake lint` effectively never terminated (the bench and mathlib CI lint timeouts).

Store the mapping as a `Thunk` on `Kernel.Environment`, filled in `finalizeImport` from the merged views: the runtime forces thunks exactly once, safely across threads (`lean_thunk_get_core` claims the closure atomically and `mark_mt`s the value), so downstream per-declaration reads are constant time again after a single fold, matching the eagerly-built field this accessor replaced. Code that manually reconstructs a `Kernel.Environment` with different views carries the old thunk, which matches how the precomputed field behaved under the same surgery.

Verified: `lake lint` on a from-scratch batteries build previously hung indefinitely in `getDeclsInPackage` and now completes.

Co-Authored-By: Claude
@leanprover-radar

leanprover-radar commented Jul 13, 2026

Copy link
Copy Markdown

Benchmark results for leanprover-community/mathlib4-nightly-testing@a04b6d1 against leanprover-community/mathlib4-nightly-testing@5edfd4c are in. There are significant results. @Kha

  • 🟥 build//instructions: +7.0T (+4.62%)

Large changes (1🟥)

  • 1 hidden

Small changes (3978🟥)

  • 🟥 build/module/Aesop.BuiltinRules.Assumption//instructions: +294.3M (+10.71%)
  • 🟥 build/module/Aesop.BuiltinRules.DestructProducts//instructions: +283.6M (+9.13%)
  • 🟥 build/module/Aesop.BuiltinRules.Split//instructions: +273.7M (+13.21%)
  • 🟥 build/module/Aesop.BuiltinRules//instructions: +270.4M (+16.81%)
  • 🟥 build/module/Aesop.Frontend.Attribute//instructions: +282.0M (+10.58%)
  • 🟥 build/module/Aesop.Frontend.Command//instructions: +290.8M (+5.86%)
  • 🟥 build/module/Aesop.Frontend.Saturate//instructions: +266.2M (+6.43%)
  • 🟥 build/module/Aesop.Main//instructions: +267.1M (+7.03%)
  • 🟥 build/module/Aesop//instructions: +257.8M (+17.03%)
  • 🟥 build/module/Batteries.Data.String.Lemmas//instructions: +1.1G (+3.21%)
  • 🟥 build/module/Mathlib.Algebra.AddConstMap.Basic//instructions: +964.1M (+3.86%)
  • 🟥 build/module/Mathlib.Algebra.AddConstMap.Equiv//instructions: +788.0M (+10.19%)
  • 🟥 build/module/Mathlib.Algebra.AddTorsor.Basic//instructions: +529.1M (+18.89%)
  • 🟥 build/module/Mathlib.Algebra.AddTorsor.Defs//instructions: +316.5M (+16.07%)
  • 🟥 build/module/Mathlib.Algebra.AffineMonoid.Basic//instructions: +611.4M (+15.66%)
  • 🟥 build/module/Mathlib.Algebra.AffineMonoid.Embedding//instructions: +931.5M (+17.62%)
  • 🟥 build/module/Mathlib.Algebra.AffineMonoid.Irreducible//instructions: +638.9M (+7.25%)
  • 🟥 build/module/Mathlib.Algebra.AffineMonoid.UniqueSums//instructions: +833.7M (+15.07%)
  • 🟥 build/module/Mathlib.Algebra.Algebra.Bilinear//instructions: +697.6M (+4.26%)
  • 🟥 build/module/Mathlib.Algebra.Algebra.Equiv//instructions: +820.1M (+1.98%)
  • and 3958 more

mathlib-nightly-testing Bot pushed a commit to leanprover-community/batteries that referenced this pull request Jul 13, 2026
@github-actions github-actions Bot added the mathlib4-nightly-available A branch for this PR exists at leanprover-community/mathlib4-nightly-testing:lean-pr-testing-NNNN label Jul 13, 2026
mathlib-nightly-testing Bot pushed a commit to leanprover-community/mathlib4-nightly-testing that referenced this pull request Jul 13, 2026
leanprover-bot added a commit to leanprover/reference-manual that referenced this pull request Jul 13, 2026
@Kha Kha force-pushed the olean-const-trie branch from 800e784 to e5ae1c9 Compare July 15, 2026 09:02
mathlib-nightly-testing Bot pushed a commit to leanprover-community/batteries that referenced this pull request Jul 15, 2026
mathlib-nightly-testing Bot pushed a commit to leanprover-community/mathlib4-nightly-testing that referenced this pull request Jul 15, 2026
leanprover-bot added a commit to leanprover/reference-manual that referenced this pull request Jul 15, 2026
The extra-constants view (codegen names consulted only when a name misses the constants view) was merged eagerly at import like the constants view, although its duplicate report is not consumed. Merge it lazily instead: a lazy node holds the candidate subtrees sharing its prefix and computes its children on first descent via a thunk, one level at a time; entry lookups at the prefix itself answer directly from the candidates. Thunk forcing is thread-safe and supported on persistent objects, so lazy nodes are safe to share across elaboration threads, and the process-global lookup cache keeps each forced walk to once per name.

This removes the extras merge (over half the total merge work) from the import path: `import Mathlib` drops 7% task-clock locally, and even extras-heavy elaboration workloads come out slightly ahead since only touched prefixes are ever merged.

Also ports the leanchecker `ReplaceAxiom` helper to the `modifyAt`/`mkMerged` API, which the new constructor's exhaustiveness requirement would otherwise break.

Co-Authored-By: Claude
@Kha

Kha commented Jul 15, 2026

Copy link
Copy Markdown
Member Author

!bench

@leanprover-radar

leanprover-radar commented Jul 15, 2026

Copy link
Copy Markdown

Benchmark results for de7e9f4 against 8006bb0 are in. There are significant results. @Kha

Warning

These warnings may indicate that the benchmark results are not directly comparable, for example due to changes in the runner configuration or hardware.

  • Bench repo commit hashes for run build differ between commits.
  • Bench repo commit hashes for run other differ between commits.
  • 🟥 build//instructions: +372.0G (+3.14%)

Large changes (51✅, 21🟥)

  • 🟥 build//maxrss: +141MiB (+15.07%)
  • 🟥 build/module/Std.Data.DHashMap.Internal.RawLemmas//instructions: +58.1G (+22.72%)
  • 🟥 build/module/Std.Data.DHashMap.RawLemmas//instructions: +7.6G (+4.93%)
  • 🟥 build/module/Std.Data.DTreeMap.Internal.Lemmas//instructions: +9.3G (+4.09%)
  • build/profile/import//wall-clock: -28s (-17.52%)
  • 🟥 build/profile/interpretation//wall-clock: +18s (+17.86%)
  • 🟥 build/stat/imported bytes//bytes: +2GiB (+9.50%)
  • 🟥 compiled/incr_header_save//maxrss: +236MiB (+11.49%)
  • 🟥 compiled/incr_header_save//task-clock: +568ms (+39.66%)
  • 🟥 compiled/incr_header_save//wall-clock: +570ms (+39.07%)
  • elab/big_beq//maxrss: -67MiB (-3.79%)
  • elab/big_beq_rec//maxrss: -65MiB (-3.65%)
  • elab/big_deceq//maxrss: -64MiB (-3.62%)
  • elab/big_deceq_rec//maxrss: -63MiB (-3.59%)
  • elab/big_do//maxrss: -127MiB (-19.83%)
  • elab/big_match//maxrss: -63MiB (-3.52%)
  • elab/big_match_nat//maxrss: -66MiB (-3.78%)
  • elab/big_match_nat//task-clock: -59ms (-12.02%)
  • elab/big_match_nat_split//maxrss: -65MiB (-3.64%)
  • elab/big_match_partial//maxrss: -65MiB (-3.61%)
  • and 51 more
  • and 1 hidden

Medium changes (33✅, 11🟥)

  • 🟥 build/lakeprof/longest rebuild path//instructions: +19.9G (+3.21%)
  • 🟥 build/module/Init.Data.BitVec.Lemmas//instructions: +1.9G (+1.53%)
  • 🟥 build/module/Std.Data.HashMap.RawLemmas//instructions: +1.4G (+1.19%)
  • 🟥 build/module/Std.Tactic.BVDecide.Bitblast.BVExpr.Circuit.Lemmas.Expr//instructions: +1.1G (+1.16%)
  • 🟥 compiled/incr_header_save//instructions: +1.3G (+23.34%)
  • elab/big_beq//task-clock: -53ms (-6.33%)
  • elab/big_beq//wall-clock: -52ms (-6.03%)
  • elab/big_deceq//instructions: -78.7M (-1.87%)
  • elab/big_deceq//task-clock: -47ms (-9.57%)
  • elab/big_deceq//wall-clock: -48ms (-9.40%)
  • elab/big_deceq_rec//instructions: -74.2M (-1.32%)
  • elab/big_deceq_rec//task-clock: -57ms (-9.24%)
  • elab/big_deceq_rec//wall-clock: -55ms (-8.67%)
  • elab/big_match//instructions: -73.2M (-0.70%)
  • elab/big_match//task-clock: -57ms (-6.25%)
  • elab/big_match//wall-clock: -57ms (-6.10%)
  • elab/big_match_nat//wall-clock: -57ms (-11.07%)
  • elab/bv_decide_mod//maxrss: -193MiB (-8.67%)
  • elab/cbv_aes//maxrss: -119MiB (-13.77%)
  • elab/cbv_decide//maxrss: -64MiB (-3.49%)
  • and 24 more

Small changes (27✅, 2476🟥)

  • 🟥 build/module/Init.BinderNameHint//instructions: +19.7M (+5.92%)
  • 🟥 build/module/Init.BinderPredicates//instructions: +65.5M (+2.99%) (reduced significance based on absolute threshold)
  • 🟥 build/module/Init.ByCases//instructions: +39.6M (+4.98%) (reduced significance based on absolute threshold)
  • 🟥 build/module/Init.CbvSimproc//instructions: +77.2M (+3.59%) (reduced significance based on absolute threshold)
  • 🟥 build/module/Init.Classical//instructions: +51.6M (+4.77%) (reduced significance based on absolute threshold)
  • 🟥 build/module/Init.Control.Basic//instructions: +44.1M (+1.97%)
  • 🟥 build/module/Init.Control.Do//instructions: +35.6M (+6.93%) (reduced significance based on absolute threshold)
  • 🟥 build/module/Init.Control.EState//instructions: +40.0M (+5.75%) (reduced significance based on absolute threshold)
  • 🟥 build/module/Init.Control.Except//instructions: +33.1M (+2.36%) (reduced significance based on absolute threshold)
  • 🟥 build/module/Init.Control.ExceptCps//instructions: +39.2M (+3.51%) (reduced significance based on absolute threshold)
  • 🟥 build/module/Init.Control.Id//instructions: +25.7M (+5.37%)
  • 🟥 build/module/Init.Control.Lawful.Basic//instructions: +51.0M (+2.34%) (reduced significance based on absolute threshold)
  • 🟥 build/module/Init.Control.Lawful.Instances//instructions: +120.4M (+1.72%) (reduced significance based on absolute threshold)
  • 🟥 build/module/Init.Control.Lawful.Lemmas//instructions: +48.5M (+6.89%) (reduced significance based on absolute threshold)
  • 🟥 build/module/Init.Control.Lawful.MonadAttach.Instances//instructions: +52.0M (+3.25%) (reduced significance based on absolute threshold)
  • 🟥 build/module/Init.Control.Lawful.MonadAttach.Lemmas//instructions: +53.1M (+5.22%) (reduced significance based on absolute threshold)
  • 🟥 build/module/Init.Control.Lawful.MonadAttach//instructions: +45.4M (+9.20%) (reduced significance based on absolute threshold)
  • 🟥 build/module/Init.Control.Lawful.MonadLift.Instances//instructions: +54.1M (+4.58%) (reduced significance based on absolute threshold)
  • 🟥 build/module/Init.Control.Lawful.MonadLift.Lemmas//instructions: +38.2M (+4.38%) (reduced significance based on absolute threshold)
  • 🟥 build/module/Init.Control.Lawful.MonadLift//instructions: +44.6M (+9.05%) (reduced significance based on absolute threshold)
  • and 2483 more

mathlib-nightly-testing Bot pushed a commit to leanprover-community/batteries that referenced this pull request Jul 15, 2026
mathlib-nightly-testing Bot pushed a commit to leanprover-community/mathlib4-nightly-testing that referenced this pull request Jul 15, 2026
leanprover-bot added a commit to leanprover/reference-manual that referenced this pull request Jul 15, 2026
@Kha

Kha commented Jul 15, 2026

Copy link
Copy Markdown
Member Author

!bench mathlib

@leanprover-radar

leanprover-radar commented Jul 15, 2026

Copy link
Copy Markdown

Benchmark results for leanprover-community/mathlib4-nightly-testing@5843b6f against leanprover-community/mathlib4-nightly-testing@5edfd4c are in. There are significant results. @Kha

  • 🟥 build//instructions: +4.3T (+2.86%)

Large changes (2🟥)

  • 🟥 lint//instructions: +7.1T (+117.94%)
  • and 1 hidden

Small changes (68🟥)

  • 🟥 build/module/Batteries.Data.String.Lemmas//instructions: +941.4M (+2.82%)
  • 🟥 build/module/Mathlib.Algebra.Category.ModuleCat.Presheaf.PushforwardZeroMonoidal//instructions: +1.5G (+1.38%)
  • 🟥 build/module/Mathlib.Algebra.Group.Action.Pi//instructions: +302.2M (+4.98%)
  • 🟥 build/module/Mathlib.Algebra.Group.NatPowAssoc//instructions: +398.7M (+7.23%)
  • 🟥 build/module/Mathlib.Algebra.Order.Field.Basic//instructions: +891.1M (+1.78%)
  • 🟥 build/module/Mathlib.Algebra.Order.Group.Pointwise.Interval//instructions: +807.5M (+1.53%)
  • 🟥 build/module/Mathlib.Algebra.Order.Kleene//instructions: +410.7M (+2.73%)
  • 🟥 build/module/Mathlib.Algebra.Order.Ring.StandardPart//instructions: +1.5G (+1.72%)
  • 🟥 build/module/Mathlib.AlgebraicGeometry.Group.Abelian//instructions: +1.3G (+2.11%)
  • 🟥 build/module/Mathlib.AlgebraicGeometry.Modules.Tilde//instructions: +3.8G (+1.24%)
  • 🟥 build/module/Mathlib.Analysis.CStarAlgebra.Matrix//instructions: +1.5G (+1.94%)
  • 🟥 build/module/Mathlib.Analysis.Complex.CanonicalDecomposition//instructions: +1.1G (+2.26%)
  • 🟥 build/module/Mathlib.Analysis.InnerProductSpace.NormDet//instructions: +1.2G (+2.00%)
  • 🟥 build/module/Mathlib.Analysis.SpecialFunctions.Complex.LogBounds//instructions: +1.5G (+2.29%)
  • 🟥 build/module/Mathlib.Analysis.SpecialFunctions.ContinuousFunctionalCalculus.Rpow.RingInverseOrder//instructions: +1.3G (+2.05%)
  • 🟥 build/module/Mathlib.CategoryTheory.ConcreteCategory.Basic//instructions: +369.2M (+5.21%)
  • 🟥 build/module/Mathlib.CategoryTheory.Functor.FullyFaithful//instructions: +461.6M (+3.80%)
  • 🟥 build/module/Mathlib.Combinatorics.Enumerative.Bell//instructions: +670.1M (+2.62%)
  • 🟥 build/module/Mathlib.Combinatorics.Enumerative.Partition.Basic//instructions: +494.9M (+4.90%)
  • 🟥 build/module/Mathlib.Combinatorics.Enumerative.Partition.Glaisher//instructions: +958.6M (+2.19%)
  • and 48 more

@Kha

Kha commented Jul 15, 2026

Copy link
Copy Markdown
Member Author

!bench

@leanprover-radar

leanprover-radar commented Jul 15, 2026

Copy link
Copy Markdown

Benchmark results for 6f3486c against 8006bb0 are in. There are significant results. @Kha

Warning

These warnings may indicate that the benchmark results are not directly comparable, for example due to changes in the runner configuration or hardware.

  • Bench repo commit hashes for run build differ between commits.
  • Bench repo commit hashes for run other differ between commits.
  • 🟥 build//instructions: +445.3G (+3.76%)

Large changes (50✅, 22🟥)

  • 🟥 build//maxrss: +138MiB (+14.78%)
  • 🟥 build/module/Std.Data.DHashMap.Internal.RawLemmas//instructions: +66.3G (+25.94%)
  • 🟥 build/module/Std.Data.DHashMap.RawLemmas//instructions: +8.1G (+5.24%)
  • 🟥 build/module/Std.Data.DTreeMap.Internal.Lemmas//instructions: +10.6G (+4.67%)
  • 🟥 build/profile/interpretation//wall-clock: +22s (+20.97%)
  • 🟥 build/profile/tactic execution//wall-clock: +1m 33s (+31.19%)
  • 🟥 build/stat/imported bytes//bytes: +2GiB (+9.52%)
  • 🟥 compiled/incr_header_save//maxrss: +200MiB (+9.76%)
  • 🟥 compiled/incr_header_save//task-clock: +230ms (+16.07%)
  • 🟥 compiled/incr_header_save//wall-clock: +233ms (+15.95%)
  • elab/big_beq//maxrss: -74MiB (-4.16%)
  • elab/big_beq_rec//maxrss: -74MiB (-4.12%)
  • elab/big_deceq//maxrss: -71MiB (-4.07%)
  • elab/big_deceq_rec//maxrss: -71MiB (-4.06%)
  • elab/big_do//maxrss: -131MiB (-20.46%)
  • elab/big_match//maxrss: -72MiB (-4.01%)
  • elab/big_match_nat//maxrss: -75MiB (-4.28%)
  • elab/big_match_nat_split//maxrss: -74MiB (-4.12%)
  • elab/big_match_partial//maxrss: -75MiB (-4.18%)
  • elab/big_omega//maxrss: -129MiB (-19.64%)
  • and 51 more
  • and 1 hidden

Medium changes (4✅, 44🟥)

  • 🟥 build//task-clock: +1m 56s (+5.51%)
  • 🟥 build/lakeprof/longest rebuild path//instructions: +23.7G (+3.83%)
  • 🟥 build/module/Init.Data.BitVec.Bitblast//instructions: +1.1G (+1.98%)
  • 🟥 build/module/Init.Data.BitVec.Lemmas//instructions: +2.1G (+1.67%)
  • 🟥 build/module/Init.Data.SInt.Lemmas//instructions: +1.1G (+1.87%)
  • 🟥 build/module/Lean.Elab.Do.Legacy//instructions: +1.0G (+2.17%) (reduced significance based on absolute threshold)
  • 🟥 build/module/Std.Data.HashMap.RawLemmas//instructions: +1.5G (+1.30%)
  • 🟥 build/module/Std.Tactic.BVDecide.Bitblast.BVExpr.Circuit.Lemmas.Expr//instructions: +1.2G (+1.32%)
  • build/profile/import//wall-clock: -21s (-13.43%)
  • 🟥 compiled/incr_header_save//instructions: +1.2G (+21.13%)
  • 🟥 elab/big_beq//instructions: +130.9M (+1.48%)
  • 🟥 elab/big_deceq//instructions: +119.7M (+2.85%)
  • 🟥 elab/big_deceq_rec//instructions: +119.9M (+2.13%)
  • 🟥 elab/big_do//instructions: +81.9M (+0.44%)
  • 🟥 elab/big_match//instructions: +124.0M (+1.19%)
  • 🟥 elab/big_match_nat//instructions: +128.6M (+2.72%)
  • 🟥 elab/big_match_partial//instructions: +132.8M (+0.96%)
  • 🟥 elab/big_struct//instructions: +49.4M (+1.92%)
  • 🟥 elab/bv_decide_rewriter//instructions: +188.0M (+2.04%)
  • elab/cbv_aes//maxrss: -127MiB (-14.70%)
  • and 28 more

Small changes (15✅, 2472🟥)

  • 🟥 build//wall-clock: +4s (+3.35%)
  • 🟥 build/module/Init.BinderNameHint//instructions: +21.3M (+6.41%)
  • 🟥 build/module/Init.BinderPredicates//instructions: +76.9M (+3.51%) (reduced significance based on absolute threshold)
  • 🟥 build/module/Init.ByCases//instructions: +43.1M (+5.41%) (reduced significance based on absolute threshold)
  • 🟥 build/module/Init.CbvSimproc//instructions: +91.0M (+4.23%) (reduced significance based on absolute threshold)
  • 🟥 build/module/Init.Classical//instructions: +57.1M (+5.28%) (reduced significance based on absolute threshold)
  • 🟥 build/module/Init.Control.Basic//instructions: +49.5M (+2.22%) (reduced significance based on absolute threshold)
  • 🟥 build/module/Init.Control.Do//instructions: +39.4M (+7.66%) (reduced significance based on absolute threshold)
  • 🟥 build/module/Init.Control.EState//instructions: +44.2M (+6.35%) (reduced significance based on absolute threshold)
  • 🟥 build/module/Init.Control.Except//instructions: +37.5M (+2.67%) (reduced significance based on absolute threshold)
  • 🟥 build/module/Init.Control.ExceptCps//instructions: +44.1M (+3.94%) (reduced significance based on absolute threshold)
  • 🟥 build/module/Init.Control.Id//instructions: +30.8M (+6.43%) (reduced significance based on absolute threshold)
  • 🟥 build/module/Init.Control.Lawful.Basic//instructions: +59.7M (+2.73%) (reduced significance based on absolute threshold)
  • 🟥 build/module/Init.Control.Lawful.Instances//instructions: +127.6M (+1.83%) (reduced significance based on absolute threshold)
  • 🟥 build/module/Init.Control.Lawful.Lemmas//instructions: +54.8M (+7.78%) (reduced significance based on absolute threshold)
  • 🟥 build/module/Init.Control.Lawful.MonadAttach.Instances//instructions: +59.1M (+3.70%) (reduced significance based on absolute threshold)
  • 🟥 build/module/Init.Control.Lawful.MonadAttach.Lemmas//instructions: +59.3M (+5.83%) (reduced significance based on absolute threshold)
  • 🟥 build/module/Init.Control.Lawful.MonadAttach//instructions: +47.4M (+9.60%) (reduced significance based on absolute threshold)
  • 🟥 build/module/Init.Control.Lawful.MonadLift.Instances//instructions: +60.9M (+5.16%) (reduced significance based on absolute threshold)
  • 🟥 build/module/Init.Control.Lawful.MonadLift.Lemmas//instructions: +47.6M (+5.45%) (reduced significance based on absolute threshold)
  • and 2467 more

mathlib-nightly-testing Bot pushed a commit to leanprover-community/batteries that referenced this pull request Jul 15, 2026
mathlib-nightly-testing Bot pushed a commit to leanprover-community/mathlib4-nightly-testing that referenced this pull request Jul 15, 2026
leanprover-bot added a commit to leanprover/reference-manual that referenced this pull request Jul 15, 2026
The imported-constant cache marked its values multi-threaded so reader threads could reference them atomically, which makes the reference count of hot values (`Eq`, `Nat`, common instances) a cache line bouncing between cores on every lookup from every elaboration thread. Add `lean_mark_persistent_unshared`, a `lean_mark_persistent` variant that skips multi-threaded objects and their subgraphs: it only writes thread-owned reference counts, so it is safe where the plain variant races, and the skipped fringe stays alive below persistent parents since `dec` never traverses persistent objects. Marking cache values with it makes hits free of atomic reference counting and of coherence traffic: 1-2% fewer cycles on elaboration workloads and 3% less CPU time on parallel-elaboration-heavy ones, at unchanged instruction counts.

Co-Authored-By: Claude
@Kha Kha force-pushed the olean-const-trie branch from 6f3486c to 5460173 Compare July 15, 2026 15:59
@Kha

Kha commented Jul 15, 2026

Copy link
Copy Markdown
Member Author

!bench

@leanprover-radar

leanprover-radar commented Jul 15, 2026

Copy link
Copy Markdown

Benchmark results for 5460173 against 8006bb0 are in. There are significant results. @Kha

Warning

These warnings may indicate that the benchmark results are not directly comparable, for example due to changes in the runner configuration or hardware.

  • Bench repo commit hashes for run build differ between commits.
  • Bench repo commit hashes for run other differ between commits.
  • 🟥 build//instructions: +353.4G (+2.98%)

Large changes (51✅, 22🟥)

  • 🟥 build//maxrss: +138MiB (+14.77%)
  • 🟥 build/module/Std.Data.DHashMap.Internal.RawLemmas//instructions: +57.9G (+22.66%)
  • 🟥 build/module/Std.Data.DHashMap.RawLemmas//instructions: +7.5G (+4.84%)
  • 🟥 build/module/Std.Data.DTreeMap.Internal.Lemmas//instructions: +9.0G (+3.95%)
  • build/profile/import//wall-clock: -29s (-17.87%)
  • 🟥 build/profile/interpretation//wall-clock: +16s (+15.59%)
  • 🟥 build/stat/imported bytes//bytes: +2GiB (+9.50%)
  • 🟥 compiled/incr_header_save//maxrss: +235MiB (+11.43%)
  • 🟥 compiled/incr_header_save//task-clock: +582ms (+40.67%)
  • 🟥 compiled/incr_header_save//wall-clock: +581ms (+39.87%)
  • elab/big_beq//maxrss: -66MiB (-3.75%)
  • elab/big_beq_rec//maxrss: -66MiB (-3.73%)
  • elab/big_deceq//maxrss: -65MiB (-3.68%)
  • elab/big_deceq_rec//maxrss: -64MiB (-3.65%)
  • elab/big_do//maxrss: -129MiB (-20.11%)
  • elab/big_match//maxrss: -66MiB (-3.70%)
  • elab/big_match_nat//maxrss: -68MiB (-3.87%)
  • elab/big_match_nat_split//maxrss: -67MiB (-3.72%)
  • elab/big_match_partial//maxrss: -68MiB (-3.77%)
  • elab/big_omega//maxrss: -126MiB (-19.11%)
  • and 52 more
  • and 1 hidden

Medium changes (30✅, 10🟥)

  • 🟥 build/lakeprof/longest rebuild path//instructions: +18.9G (+3.06%)
  • 🟥 build/module/Init.Data.BitVec.Lemmas//instructions: +1.7G (+1.36%)
  • 🟥 build/module/Std.Tactic.BVDecide.Bitblast.BVExpr.Circuit.Lemmas.Expr//instructions: +1.0G (+1.07%)
  • 🟥 compiled/incr_header_save//instructions: +1.3G (+23.33%)
  • elab/big_beq//task-clock: -52ms (-6.23%)
  • elab/big_beq//wall-clock: -51ms (-6.00%)
  • elab/big_deceq//instructions: -80.2M (-1.91%)
  • elab/big_deceq//task-clock: -52ms (-10.53%)
  • elab/big_deceq//wall-clock: -52ms (-10.18%)
  • elab/big_deceq_rec//instructions: -77.6M (-1.38%)
  • elab/big_deceq_rec//wall-clock: -50ms (-7.97%)
  • elab/big_match//instructions: -74.5M (-0.72%)
  • elab/big_match//task-clock: -60ms (-6.56%)
  • elab/big_match//wall-clock: -57ms (-6.16%)
  • elab/big_match_nat//task-clock: -56ms (-11.25%)
  • elab/big_match_nat//wall-clock: -55ms (-10.62%)
  • elab/cbv_aes//maxrss: -130MiB (-15.06%)
  • elab/delayed_assign//instructions: -88.3M (-2.64%)
  • elab/delayed_assign//task-clock: -51ms (-12.27%)
  • elab/delayed_assign//wall-clock: -48ms (-11.52%)
  • and 20 more

Small changes (30✅, 2475🟥)

  • 🟥 build/module/Init.BinderNameHint//instructions: +18.1M (+5.44%)
  • 🟥 build/module/Init.BinderPredicates//instructions: +61.3M (+2.80%) (reduced significance based on absolute threshold)
  • 🟥 build/module/Init.ByCases//instructions: +37.0M (+4.64%)
  • 🟥 build/module/Init.CbvSimproc//instructions: +71.1M (+3.31%) (reduced significance based on absolute threshold)
  • 🟥 build/module/Init.Classical//instructions: +47.2M (+4.37%) (reduced significance based on absolute threshold)
  • 🟥 build/module/Init.Control.Basic//instructions: +41.7M (+1.87%)
  • 🟥 build/module/Init.Control.Do//instructions: +34.5M (+6.73%) (reduced significance based on absolute threshold)
  • 🟥 build/module/Init.Control.EState//instructions: +38.2M (+5.48%) (reduced significance based on absolute threshold)
  • 🟥 build/module/Init.Control.Except//instructions: +33.8M (+2.41%) (reduced significance based on absolute threshold)
  • 🟥 build/module/Init.Control.ExceptCps//instructions: +37.7M (+3.37%) (reduced significance based on absolute threshold)
  • 🟥 build/module/Init.Control.Id//instructions: +25.9M (+5.41%)
  • 🟥 build/module/Init.Control.Lawful.Basic//instructions: +47.6M (+2.18%) (reduced significance based on absolute threshold)
  • 🟥 build/module/Init.Control.Lawful.Instances//instructions: +104.2M (+1.49%) (reduced significance based on absolute threshold)
  • 🟥 build/module/Init.Control.Lawful.Lemmas//instructions: +45.8M (+6.51%) (reduced significance based on absolute threshold)
  • 🟥 build/module/Init.Control.Lawful.MonadAttach.Instances//instructions: +49.2M (+3.08%) (reduced significance based on absolute threshold)
  • 🟥 build/module/Init.Control.Lawful.MonadAttach.Lemmas//instructions: +47.9M (+4.70%)
  • 🟥 build/module/Init.Control.Lawful.MonadAttach//instructions: +43.6M (+8.83%) (reduced significance based on absolute threshold)
  • 🟥 build/module/Init.Control.Lawful.MonadLift.Instances//instructions: +51.9M (+4.40%) (reduced significance based on absolute threshold)
  • 🟥 build/module/Init.Control.Lawful.MonadLift.Lemmas//instructions: +36.5M (+4.18%)
  • 🟥 build/module/Init.Control.Lawful.MonadLift//instructions: +43.3M (+8.78%) (reduced significance based on absolute threshold)
  • and 2485 more

mathlib-nightly-testing Bot pushed a commit to leanprover-community/batteries that referenced this pull request Jul 15, 2026
mathlib-nightly-testing Bot pushed a commit to leanprover-community/mathlib4-nightly-testing that referenced this pull request Jul 15, 2026
leanprover-bot added a commit to leanprover/reference-manual that referenced this pull request Jul 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaks-mathlib This is not necessarily a blocker for merging: but there needs to be a plan builds-manual CI has verified that the Lean Language Reference builds against this PR mathlib4-nightly-available A branch for this PR exists at leanprover-community/mathlib4-nightly-testing:lean-pr-testing-NNNN toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants