Skip to content

perf: normalize free variables in the type class resolution cache key - #14369

Draft
Kha wants to merge 22 commits into
masterfrom
push-umqqwtmwmmyx
Draft

perf: normalize free variables in the type class resolution cache key#14369
Kha wants to merge 22 commits into
masterfrom
push-umqqwtmwmmyx

Conversation

@Kha

@Kha Kha commented Jul 12, 2026

Copy link
Copy Markdown
Member

Based on #14316

@Kha

Kha commented Jul 12, 2026

Copy link
Copy Markdown
Member Author

!bench mathlib

@leanprover-radar

leanprover-radar commented Jul 12, 2026

Copy link
Copy Markdown

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

  • build//instructions: -8.5T (-5.60%)

Large changes (79✅, 1🟥)

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

Medium changes (497✅, 1🟥)

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

Small changes (1199✅, 2🟥)

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 12, 2026
@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 12, 2026
@leanprover-bot

leanprover-bot commented Jul 12, 2026

Copy link
Copy Markdown
Collaborator

Reference manual CI status:

  • 💥 Reference manual branch lean-pr-testing-14369 build failed against this PR. (2026-07-12 18:52:41) View Log
  • 🟡 Reference manual branch lean-pr-testing-14369 build against this PR didn't complete normally. (2026-07-12 18:52:54) View Log
  • 💥 Reference manual branch lean-pr-testing-14369 build failed against this PR. (2026-07-12 20:20:13) View Log
  • 🟡 Reference manual branch lean-pr-testing-14369 build against this PR didn't complete normally. (2026-07-12 20:21:37) View Log
  • 💥 Reference manual branch lean-pr-testing-14369 build failed against this PR. (2026-07-23 17:14:45) View Log
  • 🟡 Reference manual branch lean-pr-testing-14369 build against this PR didn't complete normally. (2026-07-23 17:16:12) View Log
  • 💥 Reference manual branch lean-pr-testing-14369 build failed against this PR. (2026-07-23 18:00:04) View Log
  • 🟡 Reference manual branch lean-pr-testing-14369 build against this PR didn't complete normally. (2026-07-23 18:00:44) View Log
  • ❗ Reference manual CI can not be attempted yet, as the nightly-testing-2026-07-22 tag does not exist there yet. We will retry when you push more commits. If you rebase your branch onto nightly-with-manual, reference manual CI should run now. You can force reference manual CI using the force-manual-ci label. (2026-07-24 10:08:17)
  • ✅ Reference manual branch lean-pr-testing-14369 has successfully built against this PR. (2026-08-09 15:52:16) View Log
  • 🟡 Reference manual branch lean-pr-testing-14369 build against this PR didn't complete normally. (2026-08-09 15:53:26) View Log

@Kha
Kha force-pushed the push-umqqwtmwmmyx branch from 2768f7d to a57255e Compare July 12, 2026 19:01
@mathlib-lean-pr-testing mathlib-lean-pr-testing Bot added the breaks-mathlib This is not necessarily a blocker for merging: but there needs to be a plan label Jul 12, 2026
@mathlib-lean-pr-testing

mathlib-lean-pr-testing Bot commented Jul 12, 2026

Copy link
Copy Markdown

Mathlib CI status (docs):

  • 💥 Mathlib branch lean-pr-testing-14369 build failed against this PR. (2026-07-12 19:34:17) View Log
  • 💥 Mathlib branch lean-pr-testing-14369 build failed against this PR. (2026-07-12 21:02:15) View Log
  • 💥 Mathlib branch lean-pr-testing-14369 build failed against this PR. (2026-07-23 17:53:36) View Log
  • 💥 Mathlib branch lean-pr-testing-14369 build failed against this PR. (2026-07-23 18:40:55) View Log
  • ❗ Mathlib CI can not be attempted yet, as the nightly-testing-2026-07-22 tag does not exist there yet. We will retry when you push more commits. If you rebase your branch onto nightly-with-mathlib, Mathlib CI should run now. You can force Mathlib CI using the force-mathlib-ci label. (2026-07-24 10:08:16)
  • ❗ Mathlib CI can not be attempted yet, as the nightly-testing-2026-07-29 tag does not exist there yet. We will retry when you push more commits. If you rebase your branch onto nightly-with-mathlib, Mathlib CI should run now. You can force Mathlib CI using the force-mathlib-ci label. (2026-08-09 15:47:11)

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

Kha commented Jul 23, 2026

Copy link
Copy Markdown
Member Author

!bench

@leanprover-radar

leanprover-radar commented Jul 23, 2026

Copy link
Copy Markdown

Benchmark results for edd7f81 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: -232.6G (-1.96%)

Large changes (8✅)

  • build/profile/typeclass inference//wall-clock: -33s (-22.23%)
  • elab/cbv_arm_ldst//instructions: -2.9G (-4.56%)
  • elab/grind_bitvec2//instructions: -4.2G (-2.94%)
  • elab/grind_list2//instructions: -2.9G (-6.55%)
  • elab/verina//instructions: -2.6G (-3.01%)
  • vcgen/GetThrowSetGrind/200/vcgen//wall-clock: -32ms (-14.41%)
  • vcgen/GetThrowSetGrind/300/vcgen//wall-clock: -51ms (-15.41%)
  • and 1 hidden

Medium changes (53✅)

  • build/lakeprof/longest rebuild path//instructions: -15.5G (-2.51%)
  • build/module/Init.Data.BitVec.Lemmas//instructions: -2.7G (-2.18%) (reduced significance based on absolute threshold)
  • build/module/Init.Data.String.Decode//instructions: -1.2G (-4.15%) (reduced significance based on absolute threshold)
  • build/module/Init.Notation//instructions: -1.5G (-9.37%) (reduced significance based on absolute threshold)
  • build/module/Lake.Build.Module//instructions: -1.3G (-3.00%) (reduced significance based on absolute threshold)
  • build/module/Lake.CLI.Main//instructions: -3.2G (-9.69%) (reduced significance based on absolute threshold)
  • build/module/Lean.Compiler.IR.EmitLLVM//instructions: -1.5G (-5.61%) (reduced significance based on absolute threshold)
  • build/module/Lean.Elab.App//instructions: -2.0G (-4.91%) (reduced significance based on absolute threshold)
  • build/module/Lean.Elab.BuiltinDo.Let//instructions: -1.1G (-10.24%) (reduced significance based on absolute threshold)
  • build/module/Lean.Elab.BuiltinNotation//instructions: -1.3G (-9.28%) (reduced significance based on absolute threshold)
  • build/module/Lean.Elab.Do.Legacy//instructions: -3.9G (-7.99%) (reduced significance based on absolute threshold)
  • build/module/Lean.Elab.DocString.Builtin//instructions: -2.9G (-6.81%) (reduced significance based on absolute threshold)
  • build/module/Lean.Elab.DocString//instructions: -2.2G (-5.23%) (reduced significance based on absolute threshold)
  • build/module/Lean.Elab.MutualInductive//instructions: -1.1G (-3.35%) (reduced significance based on absolute threshold)
  • build/module/Lean.Elab.Quotation//instructions: -1.1G (-4.85%) (reduced significance based on absolute threshold)
  • build/module/Lean.Elab.StructInst//instructions: -1.5G (-4.60%) (reduced significance based on absolute threshold)
  • build/module/Lean.Elab.Structure//instructions: -2.1G (-5.88%) (reduced significance based on absolute threshold)
  • build/module/Lean.Elab.Tactic.BuiltinTactic//instructions: -1.5G (-8.02%) (reduced significance based on absolute threshold)
  • build/module/Lean.Elab.Tactic.Do.Internal.VCGen.Solve//instructions: -1.8G (-8.81%)
  • build/module/Lean.Elab.Tactic.Do.VCGen//instructions: -1.8G (-7.40%) (reduced significance based on absolute threshold)
  • and 33 more

Small changes (943✅, 9🟥)

  • build/module/Init.BinderPredicates//instructions: -123.6M (-5.64%) (reduced significance based on absolute threshold)
  • build/module/Init.CbvSimproc//instructions: -56.7M (-2.64%) (reduced significance based on absolute threshold)
  • build/module/Init.Control.Basic//instructions: -73.2M (-3.28%) (reduced significance based on absolute threshold)
  • build/module/Init.Conv//instructions: -204.1M (-5.31%) (reduced significance based on absolute threshold)
  • build/module/Init.Core//instructions: -281.3M (-2.79%) (reduced significance based on absolute threshold)
  • build/module/Init.Data.Array.Basic//instructions: -79.5M (-0.71%)
  • build/module/Init.Data.Array.BinSearch//instructions: -59.7M (-0.90%)
  • build/module/Init.Data.Array.Erase//instructions: -52.7M (-0.70%)
  • build/module/Init.Data.Array.Find//instructions: -73.9M (-0.73%)
  • build/module/Init.Data.Array.InsertIdx//instructions: -19.9M (-0.72%)
  • build/module/Init.Data.Array.Int//instructions: -31.0M (-2.99%)
  • build/module/Init.Data.Array.Lemmas//instructions: -218.6M (-0.39%)
  • 🟥 build/module/Init.Data.Array.Lex.Lemmas//instructions: +218.5M (+2.13%) (reduced significance based on absolute threshold)
  • build/module/Init.Data.Array.Mem//instructions: -31.0M (-2.53%)
  • build/module/Init.Data.Array.Nat//instructions: -15.7M (-1.37%)
  • build/module/Init.Data.Array.Range//instructions: -48.9M (-1.17%)
  • build/module/Init.Data.Array.Subarray//instructions: -17.0M (-0.92%)
  • build/module/Init.Data.BitVec.Basic//instructions: -80.0M (-2.08%)
  • build/module/Init.Data.BitVec.Bitblast//instructions: -973.5M (-1.77%) (reduced significance based on absolute threshold)
  • build/module/Init.Data.BitVec.Bootstrap//instructions: -21.2M (-0.75%)
  • and 932 more

@Kha Kha removed the mathlib4-nightly-available A branch for this PR exists at leanprover-community/mathlib4-nightly-testing:lean-pr-testing-NNNN label Jul 23, 2026
@Kha

Kha commented Jul 23, 2026

Copy link
Copy Markdown
Member Author

!bench mathlib

@leanprover-radar

leanprover-radar commented Jul 23, 2026

Copy link
Copy Markdown

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

  • build//instructions: -8.3T (-5.47%)

Large changes (74✅, 1🟥)

  • build/module/Mathlib.Algebra.Algebra.NonUnitalSubalgebra//instructions: -11.5G (-16.69%)
  • build/module/Mathlib.Algebra.Group.Irreducible.Indecomposable//instructions: -13.6G (-30.95%)
  • build/module/Mathlib.Algebra.Module.Torsion.PrimaryComponent//instructions: -29.1G (-44.23%)
  • build/module/Mathlib.Algebra.MonoidAlgebra.PointwiseSMul//instructions: -12.1G (-49.53%)
  • build/module/Mathlib.Algebra.Order.Group.Pointwise.Interval//instructions: -7.4G (-14.08%)
  • build/module/Mathlib.Algebra.Order.Monoid.Canonical.Basic//instructions: -10.3G (-33.05%)
  • build/module/Mathlib.Algebra.Order.ToIntervalMod//instructions: -19.3G (-25.07%)
  • build/module/Mathlib.Algebra.Polynomial.RuleOfSigns//instructions: -17.2G (-30.83%)
  • build/module/Mathlib.Algebra.Ring.CentroidHom//instructions: -8.8G (-25.80%)
  • build/module/Mathlib.Algebra.Star.NonUnitalSubalgebra//instructions: -26.7G (-24.88%)
  • build/module/Mathlib.Algebra.TrivSqZeroExt.Basic//instructions: -11.5G (-15.95%)
  • build/module/Mathlib.Analysis.Analytic.Basic//instructions: -46.7G (-38.44%)
  • build/module/Mathlib.Analysis.Analytic.CPolynomial//instructions: -21.0G (-40.99%)
  • build/module/Mathlib.Analysis.Analytic.CPolynomialDef//instructions: -21.0G (-40.80%)
  • build/module/Mathlib.Analysis.Analytic.Constructions//instructions: -45.7G (-36.20%)
  • build/module/Mathlib.Analysis.Analytic.ConvergenceRadius//instructions: -19.6G (-33.73%)
  • build/module/Mathlib.Analysis.Asymptotics.TVS//instructions: -20.7G (-28.91%)
  • build/module/Mathlib.Analysis.CStarAlgebra.ApproximateUnit//instructions: -20.1G (-27.93%)
  • build/module/Mathlib.Analysis.CStarAlgebra.ContinuousFunctionalCalculus.Continuity//instructions: -27.6G (-24.60%)
  • build/module/Mathlib.Analysis.CStarAlgebra.ContinuousFunctionalCalculus.Instances//instructions: -22.7G (-24.46%)
  • and 54 more
  • and 1 hidden

Medium changes (448✅, 1🟥)

  • build/module/Batteries.Data.List.Lemmas//instructions: -2.8G (-6.10%)
  • build/module/Mathlib.Algebra.Algebra.Bilinear//instructions: -2.3G (-13.92%)
  • build/module/Mathlib.Algebra.Algebra.NonUnitalHom//instructions: -4.3G (-16.00%)
  • build/module/Mathlib.Algebra.Algebra.Operations//instructions: -5.1G (-9.52%)
  • build/module/Mathlib.Algebra.Algebra.Spectrum.Quasispectrum//instructions: -3.7G (-10.86%)
  • build/module/Mathlib.Algebra.Algebra.Subalgebra.Rank//instructions: -4.0G (-30.73%)
  • build/module/Mathlib.Algebra.Algebra.Unitization//instructions: -5.9G (-12.55%)
  • build/module/Mathlib.Algebra.BigOperators.Fin//instructions: -6.2G (-11.51%)
  • build/module/Mathlib.Algebra.Category.ModuleCat.Presheaf.Sheafify//instructions: -6.0G (-11.34%)
  • build/module/Mathlib.Algebra.DirectSum.Internal//instructions: -4.0G (-10.55%)
  • build/module/Mathlib.Algebra.DualQuaternion//instructions: -2.8G (-15.52%)
  • build/module/Mathlib.Algebra.Exact.Basic//instructions: -2.9G (-7.25%)
  • build/module/Mathlib.Algebra.FiveLemma//instructions: -3.1G (-14.42%)
  • build/module/Mathlib.Algebra.Homology.Factorizations.CM5a//instructions: -3.5G (-6.29%)
  • build/module/Mathlib.Algebra.Lie.Basis//instructions: -14.4G (-13.61%)
  • build/module/Mathlib.Algebra.Lie.CartanCriterion//instructions: -4.0G (-9.61%)
  • build/module/Mathlib.Algebra.Lie.CartanExists//instructions: -3.9G (-11.87%)
  • build/module/Mathlib.Algebra.Lie.Loop//instructions: -4.9G (-14.86%)
  • build/module/Mathlib.Algebra.Lie.Submodule//instructions: -5.5G (-9.36%)
  • build/module/Mathlib.Algebra.Lie.Weights.Cartan//instructions: -4.4G (-11.70%)
  • and 429 more

Small changes (1173✅, 2🟥)

  • build/module/Aesop.Saturate//instructions: -687.1M (-4.66%)
  • build/module/Aesop.Script.SpecificTactics//instructions: -906.6M (-10.09%)
  • build/module/Aesop.Search.Expansion.Norm//instructions: -536.3M (-4.08%)
  • build/module/Aesop.Search.Main//instructions: -413.0M (-4.01%)
  • build/module/Aesop.Tree.ExtractScript//instructions: -456.9M (-7.79%)
  • build/module/Batteries.Data.Fin.Lemmas//instructions: -468.7M (-5.72%)
  • build/module/Batteries.Tactic.GeneralizeProofs//instructions: -405.2M (-3.27%)
  • build/module/Batteries.Tactic.SqueezeScope//instructions: -562.4M (-6.50%)
  • build/module/Mathlib.Algebra.AddConstMap.Basic//instructions: -1.9G (-7.52%)
  • build/module/Mathlib.Algebra.Algebra.Basic//instructions: -996.0M (-4.01%)
  • build/module/Mathlib.Algebra.Algebra.Equiv//instructions: -1.6G (-3.75%)
  • build/module/Mathlib.Algebra.Algebra.Hom//instructions: -709.3M (-3.51%)
  • build/module/Mathlib.Algebra.Algebra.Spectrum.Basic//instructions: -1.5G (-5.60%)
  • build/module/Mathlib.Algebra.Algebra.Subalgebra.Basic//instructions: -1.2G (-2.49%)
  • build/module/Mathlib.Algebra.Algebra.Subalgebra.Lattice//instructions: -1.3G (-3.15%)
  • build/module/Mathlib.Algebra.Algebra.Subalgebra.Unitization//instructions: -1.7G (-7.10%)
  • build/module/Mathlib.Algebra.Algebra.Tower//instructions: -1.3G (-6.39%)
  • build/module/Mathlib.Algebra.Azumaya.Matrix//instructions: -1.4G (-8.63%)
  • build/module/Mathlib.Algebra.BigOperators.Expect//instructions: -1.2G (-5.95%)
  • build/module/Mathlib.Algebra.BigOperators.Finprod//instructions: -3.6G (-6.79%)
  • and 1155 more

@Kha
Kha force-pushed the push-umqqwtmwmmyx branch from edd7f81 to 72a4b51 Compare July 23, 2026 17:04
@Kha

Kha commented Jul 23, 2026

Copy link
Copy Markdown
Member Author

!bench

@leanprover-radar

leanprover-radar commented Jul 23, 2026

Copy link
Copy Markdown

Benchmark results for 72a4b51 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: -287.0G (-2.42%)

Large changes (11✅)

  • build/module/Std.Data.DTreeMap.Internal.Lemmas//instructions: -5.8G (-2.54%)
  • build/profile/typeclass inference//wall-clock: -43s (-29.36%)
  • elab/cbv_arm_ldst//instructions: -3.0G (-4.57%)
  • elab/grind_bitvec2//instructions: -12.7G (-8.76%)
  • elab/grind_list2//instructions: -4.4G (-10.16%)
  • elab/verina//instructions: -3.6G (-4.20%)
  • misc/import Init.Data.BitVec.Lemmas//instructions: -4.8G (-4.19%)
  • misc/import Std.Data.Internal.List.Associative//instructions: -3.3G (-4.85%)
  • vcgen/GetThrowSetGrind/200/vcgen//wall-clock: -32ms (-14.41%)
  • vcgen/GetThrowSetGrind/300/vcgen//wall-clock: -51ms (-15.41%)
  • and 1 hidden

Medium changes (68✅, 3🟥)

  • build/lakeprof/longest rebuild path//instructions: -18.9G (-3.06%)
  • build/module/Init.Data.BitVec.Bitblast//instructions: -1.6G (-2.95%) (reduced significance based on absolute threshold)
  • build/module/Init.Data.BitVec.Lemmas//instructions: -4.7G (-3.79%) (reduced significance based on absolute threshold)
  • build/module/Init.Data.Int.DivMod.Lemmas//instructions: -1.6G (-4.02%) (reduced significance based on absolute threshold)
  • build/module/Init.Data.Range.Polymorphic.IntLemmas//instructions: -1.3G (-4.43%) (reduced significance based on absolute threshold)
  • build/module/Init.Data.Range.Polymorphic.NatLemmas//instructions: -1.3G (-3.82%) (reduced significance based on absolute threshold)
  • build/module/Init.Data.SInt.Lemmas//instructions: -1.3G (-2.30%)
  • build/module/Init.Data.String.Decode//instructions: -1.4G (-4.88%) (reduced significance based on absolute threshold)
  • build/module/Init.Notation//instructions: -1.5G (-9.38%) (reduced significance based on absolute threshold)
  • build/module/Lake.Build.Module//instructions: -1.4G (-3.32%) (reduced significance based on absolute threshold)
  • build/module/Lake.CLI.Main//instructions: -3.3G (-9.75%) (reduced significance based on absolute threshold)
  • build/module/Lean.Compiler.IR.EmitLLVM//instructions: -1.6G (-5.81%) (reduced significance based on absolute threshold)
  • build/module/Lean.Elab.App//instructions: -2.5G (-6.18%) (reduced significance based on absolute threshold)
  • build/module/Lean.Elab.BuiltinDo.Let//instructions: -1.1G (-10.31%) (reduced significance based on absolute threshold)
  • build/module/Lean.Elab.BuiltinNotation//instructions: -1.3G (-9.39%) (reduced significance based on absolute threshold)
  • build/module/Lean.Elab.Do.Legacy//instructions: -3.9G (-7.99%) (reduced significance based on absolute threshold)
  • build/module/Lean.Elab.DocString.Builtin//instructions: -3.3G (-7.77%) (reduced significance based on absolute threshold)
  • build/module/Lean.Elab.DocString//instructions: -2.4G (-5.63%) (reduced significance based on absolute threshold)
  • build/module/Lean.Elab.MutualDef//instructions: -1.1G (-3.83%) (reduced significance based on absolute threshold)
  • build/module/Lean.Elab.MutualInductive//instructions: -1.1G (-3.58%) (reduced significance based on absolute threshold)
  • and 51 more

Small changes (1022✅, 11🟥)

  • build/module/Init.BinderPredicates//instructions: -123.2M (-5.62%) (reduced significance based on absolute threshold)
  • build/module/Init.CbvSimproc//instructions: -56.5M (-2.63%) (reduced significance based on absolute threshold)
  • build/module/Init.Control.Basic//instructions: -73.6M (-3.29%) (reduced significance based on absolute threshold)
  • build/module/Init.Control.Lawful.Instances//instructions: -36.0M (-0.52%)
  • build/module/Init.Control.Lawful.MonadLift.Instances//instructions: -11.2M (-0.95%)
  • build/module/Init.Control.Lawful.MonadLift.Lemmas//instructions: -14.3M (-1.64%)
  • build/module/Init.Conv//instructions: -206.9M (-5.38%) (reduced significance based on absolute threshold)
  • build/module/Init.Core//instructions: -287.7M (-2.86%) (reduced significance based on absolute threshold)
  • build/module/Init.Data.Array.Basic//instructions: -105.3M (-0.94%) (reduced significance based on absolute threshold)
  • build/module/Init.Data.Array.BinSearch//instructions: -63.3M (-0.96%)
  • build/module/Init.Data.Array.Erase//instructions: -65.4M (-0.87%)
  • build/module/Init.Data.Array.Find//instructions: -121.4M (-1.20%) (reduced significance based on absolute threshold)
  • build/module/Init.Data.Array.InsertIdx//instructions: -27.8M (-1.00%)
  • build/module/Init.Data.Array.Int//instructions: -38.0M (-3.66%)
  • build/module/Init.Data.Array.Lemmas//instructions: -401.6M (-0.71%) (reduced significance based on absolute threshold)
  • 🟥 build/module/Init.Data.Array.Lex.Lemmas//instructions: +211.6M (+2.06%) (reduced significance based on absolute threshold)
  • build/module/Init.Data.Array.MapIdx//instructions: -36.2M (-0.40%)
  • build/module/Init.Data.Array.Mem//instructions: -30.6M (-2.49%)
  • build/module/Init.Data.Array.Monadic//instructions: -33.4M (-0.54%)
  • build/module/Init.Data.Array.Nat//instructions: -21.0M (-1.84%)
  • and 1013 more

@Kha

Kha commented Jul 23, 2026

Copy link
Copy Markdown
Member Author

!bench mathlib

@leanprover-radar

Copy link
Copy Markdown

Benchmark results for leanprover-community/mathlib4-nightly-testing@d166862 against leanprover-community/mathlib4-nightly-testing@5edfd4c are in. (These commits have already been benchmarked in a previous command.) There are significant results. @Kha

  • build//instructions: -8.3T (-5.47%)

Large changes (74✅, 1🟥)

  • build/module/Mathlib.Algebra.Algebra.NonUnitalSubalgebra//instructions: -11.5G (-16.69%)
  • build/module/Mathlib.Algebra.Group.Irreducible.Indecomposable//instructions: -13.6G (-30.95%)
  • build/module/Mathlib.Algebra.Module.Torsion.PrimaryComponent//instructions: -29.1G (-44.23%)
  • build/module/Mathlib.Algebra.MonoidAlgebra.PointwiseSMul//instructions: -12.1G (-49.53%)
  • build/module/Mathlib.Algebra.Order.Group.Pointwise.Interval//instructions: -7.4G (-14.08%)
  • build/module/Mathlib.Algebra.Order.Monoid.Canonical.Basic//instructions: -10.3G (-33.05%)
  • build/module/Mathlib.Algebra.Order.ToIntervalMod//instructions: -19.3G (-25.07%)
  • build/module/Mathlib.Algebra.Polynomial.RuleOfSigns//instructions: -17.2G (-30.83%)
  • build/module/Mathlib.Algebra.Ring.CentroidHom//instructions: -8.8G (-25.80%)
  • build/module/Mathlib.Algebra.Star.NonUnitalSubalgebra//instructions: -26.7G (-24.88%)
  • build/module/Mathlib.Algebra.TrivSqZeroExt.Basic//instructions: -11.5G (-15.95%)
  • build/module/Mathlib.Analysis.Analytic.Basic//instructions: -46.7G (-38.44%)
  • build/module/Mathlib.Analysis.Analytic.CPolynomial//instructions: -21.0G (-40.99%)
  • build/module/Mathlib.Analysis.Analytic.CPolynomialDef//instructions: -21.0G (-40.80%)
  • build/module/Mathlib.Analysis.Analytic.Constructions//instructions: -45.7G (-36.20%)
  • build/module/Mathlib.Analysis.Analytic.ConvergenceRadius//instructions: -19.6G (-33.73%)
  • build/module/Mathlib.Analysis.Asymptotics.TVS//instructions: -20.7G (-28.91%)
  • build/module/Mathlib.Analysis.CStarAlgebra.ApproximateUnit//instructions: -20.1G (-27.93%)
  • build/module/Mathlib.Analysis.CStarAlgebra.ContinuousFunctionalCalculus.Continuity//instructions: -27.6G (-24.60%)
  • build/module/Mathlib.Analysis.CStarAlgebra.ContinuousFunctionalCalculus.Instances//instructions: -22.7G (-24.46%)
  • and 54 more
  • and 1 hidden

Medium changes (448✅, 1🟥)

  • build/module/Batteries.Data.List.Lemmas//instructions: -2.8G (-6.10%)
  • build/module/Mathlib.Algebra.Algebra.Bilinear//instructions: -2.3G (-13.92%)
  • build/module/Mathlib.Algebra.Algebra.NonUnitalHom//instructions: -4.3G (-16.00%)
  • build/module/Mathlib.Algebra.Algebra.Operations//instructions: -5.1G (-9.52%)
  • build/module/Mathlib.Algebra.Algebra.Spectrum.Quasispectrum//instructions: -3.7G (-10.86%)
  • build/module/Mathlib.Algebra.Algebra.Subalgebra.Rank//instructions: -4.0G (-30.73%)
  • build/module/Mathlib.Algebra.Algebra.Unitization//instructions: -5.9G (-12.55%)
  • build/module/Mathlib.Algebra.BigOperators.Fin//instructions: -6.2G (-11.51%)
  • build/module/Mathlib.Algebra.Category.ModuleCat.Presheaf.Sheafify//instructions: -6.0G (-11.34%)
  • build/module/Mathlib.Algebra.DirectSum.Internal//instructions: -4.0G (-10.55%)
  • build/module/Mathlib.Algebra.DualQuaternion//instructions: -2.8G (-15.52%)
  • build/module/Mathlib.Algebra.Exact.Basic//instructions: -2.9G (-7.25%)
  • build/module/Mathlib.Algebra.FiveLemma//instructions: -3.1G (-14.42%)
  • build/module/Mathlib.Algebra.Homology.Factorizations.CM5a//instructions: -3.5G (-6.29%)
  • build/module/Mathlib.Algebra.Lie.Basis//instructions: -14.4G (-13.61%)
  • build/module/Mathlib.Algebra.Lie.CartanCriterion//instructions: -4.0G (-9.61%)
  • build/module/Mathlib.Algebra.Lie.CartanExists//instructions: -3.9G (-11.87%)
  • build/module/Mathlib.Algebra.Lie.Loop//instructions: -4.9G (-14.86%)
  • build/module/Mathlib.Algebra.Lie.Submodule//instructions: -5.5G (-9.36%)
  • build/module/Mathlib.Algebra.Lie.Weights.Cartan//instructions: -4.4G (-11.70%)
  • and 429 more

Small changes (1173✅, 2🟥)

  • build/module/Aesop.Saturate//instructions: -687.1M (-4.66%)
  • build/module/Aesop.Script.SpecificTactics//instructions: -906.6M (-10.09%)
  • build/module/Aesop.Search.Expansion.Norm//instructions: -536.3M (-4.08%)
  • build/module/Aesop.Search.Main//instructions: -413.0M (-4.01%)
  • build/module/Aesop.Tree.ExtractScript//instructions: -456.9M (-7.79%)
  • build/module/Batteries.Data.Fin.Lemmas//instructions: -468.7M (-5.72%)
  • build/module/Batteries.Tactic.GeneralizeProofs//instructions: -405.2M (-3.27%)
  • build/module/Batteries.Tactic.SqueezeScope//instructions: -562.4M (-6.50%)
  • build/module/Mathlib.Algebra.AddConstMap.Basic//instructions: -1.9G (-7.52%)
  • build/module/Mathlib.Algebra.Algebra.Basic//instructions: -996.0M (-4.01%)
  • build/module/Mathlib.Algebra.Algebra.Equiv//instructions: -1.6G (-3.75%)
  • build/module/Mathlib.Algebra.Algebra.Hom//instructions: -709.3M (-3.51%)
  • build/module/Mathlib.Algebra.Algebra.Spectrum.Basic//instructions: -1.5G (-5.60%)
  • build/module/Mathlib.Algebra.Algebra.Subalgebra.Basic//instructions: -1.2G (-2.49%)
  • build/module/Mathlib.Algebra.Algebra.Subalgebra.Lattice//instructions: -1.3G (-3.15%)
  • build/module/Mathlib.Algebra.Algebra.Subalgebra.Unitization//instructions: -1.7G (-7.10%)
  • build/module/Mathlib.Algebra.Algebra.Tower//instructions: -1.3G (-6.39%)
  • build/module/Mathlib.Algebra.Azumaya.Matrix//instructions: -1.4G (-8.63%)
  • build/module/Mathlib.Algebra.BigOperators.Expect//instructions: -1.2G (-5.95%)
  • build/module/Mathlib.Algebra.BigOperators.Finprod//instructions: -3.6G (-6.79%)
  • and 1155 more

mathlib-nightly-testing Bot pushed a commit to leanprover-community/batteries that referenced this pull request Jul 23, 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 23, 2026
mathlib-nightly-testing Bot pushed a commit to leanprover-community/mathlib4-nightly-testing that referenced this pull request Jul 23, 2026
leanprover-bot added a commit to leanprover/reference-manual that referenced this pull request Jul 23, 2026
@Kha

Kha commented Jul 23, 2026

Copy link
Copy Markdown
Member Author

!bench mathlib

@leanprover-radar

leanprover-radar commented Jul 23, 2026

Copy link
Copy Markdown

Benchmark results for leanprover-community/mathlib4-nightly-testing@c8c70aa 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 commented Jul 23, 2026

Copy link
Copy Markdown
Member Author

!bench mathlib

@leanprover-radar

Copy link
Copy Markdown

Benchmark results for leanprover-community/mathlib4-nightly-testing@c8c70aa against leanprover-community/mathlib4-nightly-testing@5edfd4c are in. (These commits have already been benchmarked in a previous command.) There are significant results. @Kha

  • 🟥 main exited with code 1

No significant changes detected.

@Kha

Kha commented Jul 24, 2026

Copy link
Copy Markdown
Member Author

!bench mathlib

@leanprover-radar

leanprover-radar commented Jul 24, 2026

Copy link
Copy Markdown

Benchmark results for 7bfafa9 against 2065c90 are in. There are significant results. @Kha

  • build//instructions: -217.8G (-1.87%)

Large changes (7✅)

  • build/profile/typeclass inference//wall-clock: -33s (-25.11%)
  • elab/cbv_arm_ldst//instructions: -2.6G (-4.56%)
  • elab/grind_bitvec2//instructions: -9.1G (-6.73%)
  • elab/grind_list2//instructions: -2.8G (-7.23%)
  • misc/import Init.Data.BitVec.Lemmas//instructions: -3.9G (-3.49%)
  • misc/import Std.Data.Internal.List.Associative//instructions: -2.7G (-4.16%)
  • and 1 hidden

Medium changes (46✅)

  • build/lakeprof/longest rebuild path//instructions: -15.9G (-2.60%)
  • build/module/Init.Data.BitVec.Bitblast//instructions: -1.2G (-2.29%) (reduced significance based on absolute threshold)
  • build/module/Init.Data.BitVec.Lemmas//instructions: -3.7G (-3.06%) (reduced significance based on absolute threshold)
  • build/module/Init.Data.Int.DivMod.Lemmas//instructions: -1.4G (-3.50%) (reduced significance based on absolute threshold)
  • build/module/Init.Data.Range.Polymorphic.IntLemmas//instructions: -1.1G (-3.98%) (reduced significance based on absolute threshold)
  • build/module/Init.Data.Range.Polymorphic.NatLemmas//instructions: -1.2G (-3.39%)
  • build/module/Init.Data.SInt.Lemmas//instructions: -1.1G (-2.00%)
  • build/module/Init.Notation//instructions: -1.2G (-8.10%) (reduced significance based on absolute threshold)
  • build/module/Lake.Build.Module//instructions: -1.2G (-2.90%) (reduced significance based on absolute threshold)
  • build/module/Lake.CLI.Main//instructions: -3.0G (-9.11%) (reduced significance based on absolute threshold)
  • build/module/Lean.Compiler.IR.EmitLLVM//instructions: -1.3G (-5.08%) (reduced significance based on absolute threshold)
  • build/module/Lean.Elab.App//instructions: -2.2G (-5.61%) (reduced significance based on absolute threshold)
  • build/module/Lean.Elab.BuiltinNotation//instructions: -1.2G (-8.68%) (reduced significance based on absolute threshold)
  • build/module/Lean.Elab.Do.Legacy//instructions: -3.0G (-6.38%) (reduced significance based on absolute threshold)
  • build/module/Lean.Elab.DocString.Builtin//instructions: -2.7G (-6.59%) (reduced significance based on absolute threshold)
  • build/module/Lean.Elab.DocString//instructions: -1.8G (-4.30%) (reduced significance based on absolute threshold)
  • build/module/Lean.Elab.StructInst//instructions: -1.6G (-4.99%) (reduced significance based on absolute threshold)
  • build/module/Lean.Elab.Structure//instructions: -1.9G (-5.43%) (reduced significance based on absolute threshold)
  • build/module/Lean.Elab.Tactic.Basic//instructions: -1.5G (-13.10%) (reduced significance based on absolute threshold)
  • build/module/Lean.Elab.Tactic.BuiltinTactic//instructions: -1.4G (-7.37%) (reduced significance based on absolute threshold)
  • and 26 more

Small changes (908✅, 68🟥)

  • build/module/Init.BinderPredicates//instructions: -102.7M (-4.84%) (reduced significance based on absolute threshold)
  • build/module/Init.CbvSimproc//instructions: -36.9M (-1.77%)
  • build/module/Init.Control.Basic//instructions: -61.6M (-2.85%) (reduced significance based on absolute threshold)
  • build/module/Init.Control.Lawful.MonadLift.Instances//instructions: -9.1M (-0.79%)
  • build/module/Init.Conv//instructions: -176.0M (-4.71%) (reduced significance based on absolute threshold)
  • build/module/Init.Core//instructions: -243.9M (-2.49%) (reduced significance based on absolute threshold)
  • build/module/Init.Data.Array.Basic//instructions: -92.4M (-0.84%)
  • build/module/Init.Data.Array.Erase//instructions: -48.4M (-0.66%)
  • build/module/Init.Data.Array.Find//instructions: -114.6M (-1.15%) (reduced significance based on absolute threshold)
  • build/module/Init.Data.Array.InsertIdx//instructions: -14.9M (-0.55%)
  • build/module/Init.Data.Array.Int//instructions: -31.5M (-3.09%)
  • build/module/Init.Data.Array.Lemmas//instructions: -311.7M (-0.57%)
  • 🟥 build/module/Init.Data.Array.Lex.Lemmas//instructions: +302.8M (+3.06%) (reduced significance based on absolute threshold)
  • build/module/Init.Data.Array.Mem//instructions: -25.6M (-2.13%)
  • build/module/Init.Data.Array.Monadic//instructions: -27.0M (-0.44%)
  • build/module/Init.Data.Array.Nat//instructions: -21.2M (-1.88%)
  • build/module/Init.Data.Array.Range//instructions: -73.5M (-1.79%) (reduced significance based on absolute threshold)
  • build/module/Init.Data.Array.Subarray//instructions: -17.0M (-0.94%)
  • build/module/Init.Data.BitVec.Basic//instructions: -96.6M (-2.58%)
  • build/module/Init.Data.BitVec.Bootstrap//instructions: -30.0M (-1.07%)
  • and 956 more

@leanprover-radar

leanprover-radar commented Jul 24, 2026

Copy link
Copy Markdown

The original message no longer contains a command.

You can edit the original message until the command succeeds.

@Kha Kha added the downstream Request a downstream-lean4 adaptation PR. label Jul 24, 2026
@downstream-lean4

downstream-lean4 Bot commented Jul 24, 2026

Copy link
Copy Markdown

The adaptation PR for this PR is leanprover/downstream-lean4#15.

@Kha
Kha force-pushed the push-umqqwtmwmmyx branch from 7bfafa9 to c6acea9 Compare July 24, 2026 13:37
@Kha
Kha force-pushed the push-umqqwtmwmmyx branch from c6acea9 to 0aeafa8 Compare July 24, 2026 17:57
@Kha Kha added the skip-tests Skip test step during PR builds label Jul 24, 2026
@Kha
Kha force-pushed the push-umqqwtmwmmyx branch 8 times, most recently from 9c96d51 to 22d7140 Compare July 31, 2026 18:21
@Kha
Kha force-pushed the push-umqqwtmwmmyx branch from 22d7140 to d959fe9 Compare August 9, 2026 15:13
leanprover-bot added a commit to leanprover/reference-manual that referenced this pull request Aug 9, 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 Aug 9, 2026
Kha and others added 8 commits August 13, 2026 04:11
This PR makes type class resolution cache entries depend on the options they observed: a query records every result-relevant option lookup (`Lean.getRecordedOption`), and an entry is served only while its recorded lookups give the same answers, so options no longer have to invalidate the cache wholesale (nor silently fail to). Options resolved once per query, such as the definitional-equality compatibility flags and the resource limits, are part of the cache key instead.

Acquiring the options plainly is what a running query forbids: `getOptions` panics while `Core.Context.recordingDeps` is set, so nothing can go unrecorded. Type class resolution is a closed system, so the few readers whose result cannot influence a cached entry acquire them through the new `MonadOptions.getOptionsUnrestricted`, each carrying its one-line argument (trace and profiler collection, message rendering, diagnostics counters, and limits whose excess throws and is never cached). The marker is scoped to the computation rather than carried by the options value or the environment, both of which outlive the query in contexts captured for later rendering.

The reachable set was measured rather than estimated: over the full `tests/elab` pile a recording query acquires the options 4.3M times from 17 source sites, all of them either audited unrestricted readers or the cache machinery itself.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…lution cache entries

This PR makes type class resolution cache entries depend on the environment state they observed, completing the dependency tracking begun with option accesses. Extensions the search consults are classified at registration: generation-tracked extensions (instances, unification hints) are read through recording accessors that log the observed generation, and covered extensions hold declaration-keyed content whose observable changes are enforced by the write machinery rather than trusted. A read of an unclassified extension during a query panics, and `tests/elab/tc_cache_covered_claims.lean` locks that audit.

Declaration-keyed writes are guarded for value stability, and a write some recording query could have observed is appended to a change log validated by constant birth ordering: the environment assigns each constant a per-lineage birth index as it becomes observable, so a change whose target was born after an entry was recorded cannot have affected it. Reducibility attribute changes are the most common such write. `debug.synthInstance.checkCacheHits` additionally re-runs served cache hits from scratch and compares, as a differential soak check.

The recording marker gains a second home on the environment (`Environment.isRecordingDeps`) alongside the scoped `Core.Context.recordingDeps` introduced with option recording. Extension reads are pure functions of an environment, with no monad to consult, so this is the only marker they can see; the two are armed together and a captured display context (messages, pretty printing) clears the environment one at the boundary.

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

Cache entries whose key contains no metavariables and whose value is closed (no free variables or abstracted metavariables in key or value) are additionally stored in a persistent tier that survives the current command, so identical queries in later commands are served from the cache instead of re-searched. The recorded dependencies introduced in the previous PR replace whole-cache invalidation entirely: an entry from an earlier command is only served while its recorded option lookups, extension generations, and reducibility statuses still give the same answers, so instance declarations, unification hints, and reducibility changes invalidate exactly the affected entries.

The persistent tier lives in a dedicated `Environment` field with branch-local value semantics: fills roll back with the environment (e.g. when a speculatively added instance is discarded), parallel elaboration branches never observe each other's fills, and a fill costs one structure copy. Context-sensitive results (metavariable-laden keys, free-variable-dependent entries) stay in the per-command tier; in particular, free-variable-keyed entries must not be persisted, as `FVarId`s recur across commands under fresh name generators (see the `tc_cache_persist_fvar` test). The behavioral test suite for dependency recording arrives here, as most of it is only observable across commands: decl-time vs post-hoc reducibility changes, option partitioning with coexisting entries, fine-grained unification-hint invalidation, and erased-instance scoping.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Persistent cache fills are environment modifications under the current storage design, so entries filled inside rolled-back regions are no longer served afterwards; the affected expectations flip from `cached:` to `new:`.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…nth`

The `#14316` merge resolved these two files to their ref-era versions, which expect `#eval`-internal type class queries to hit entries persisted by earlier commands. Under the trust-tier persistent cache, `#eval` rolls back its environment changes including cache fills, so these queries search anew each time.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Free-variable normalization re-instantiates the stored result schema on every cache hit (`SynthNorm.reopen`), so repeated queries in one context receive structurally equal but pointer-distinct instance terms. Consumers that rely on pointer identity for cheap sharing pay deep structural work per copy: `grind`'s alpha-sharing made `Mathlib.Logic.Equiv.Prod` 2.2x slower (one `grind` proof 3.0s -> 6.7s, the file +96% instructions in the full-Mathlib bench) with byte-identical query traces.

This PR therefore additionally memoizes the context-level (reopened) result under the unnormalized key in the transient tier, so repeated queries in one context return the same object, exactly as before normalization; cross-context sharing via the normalized key is unchanged. This also restores within-context caching for results that escape the normalization closure, which the normalized tiers cannot hold. Guarded by the new option `backward.synthInstance.rawKeyCache`.

With the fix, `Mathlib.Logic.Equiv.Prod` returns to parity (73.2G -> 34.6G instructions locally) and the standard bench file set is unchanged within noise.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…y cache unconditionally

The option was a debugging aid while validating the raw-key front-cache; there is no backward-compatibility reason to toggle it.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@Kha
Kha force-pushed the push-umqqwtmwmmyx branch from d959fe9 to e4b5359 Compare August 13, 2026 04:16
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 downstream Request a downstream-lean4 adaptation PR. skip-tests Skip test step during PR builds 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