Skip to content

perf: optimize compile times, peak memory, and .olean size across 32 StacksFrontier modules - #27

Open
Jakob Oesinghaus (joesinghaus) wants to merge 1 commit into
AxiomMath:mainfrom
joesinghaus:perf/compile-time-and-memory
Open

Jakob Oesinghaus (joesinghaus) wants to merge 1 commit into
AxiomMath:mainfrom
joesinghaus:perf/compile-time-and-memory

Conversation

@joesinghaus

@joesinghaus Jakob Oesinghaus (joesinghaus) commented Nov 28, 2026 •

Copy link
Copy Markdown

Summary

This PR reduces compile times, peak memory usage, and .olean sizes across 32 StacksFrontier modules (rebased onto Lean v4.36.0 / main) without changing any user-facing public declaration signatures.

  • 28 remaining heartbeat overrides eliminated (100% of heartbeat overrides in these 32 modules):
    • maxHeartbeats: 2× 8M, 3× 4M, 5× 2M, 6× 1.6M, 1× 1.5M, 8× 1M, 1× 800k (26 → 0, 100% removed)
    • synthInstance.maxHeartbeats: 1× 1M, 1× 400k (2 → 0, 100% removed)
    • maxRecDepth 4096: 1 removed
    • backward.isDefEq.respectTransparency false: 4 removed (MinimalPrimes: 1→0, PurelyInseparableCriterion: 3→0), plus file-wide respectTransparency false in CohomologyPresheafLocallyZero.lean (covering 65 declarations) scoped down to 6 individual declarations
  • Eliminated extreme memory/CPU cliffs and heavyweight imports on 16 GB machines:
    • RingTheory/MilnorPatching/Relative.lean: eliminated remaining maxHeartbeats 8000000 on extensionOfScalarsToTensorProductPullback_iso_one_tmul
    • Algebra/Category/ModuleCat/Sheaf/LocallyFreeRank.lean: eliminated maxHeartbeats 4000000 on stalk_restrictMod_linearEquiv by extracting restrictStalkRingEquiv_germ and replacing the slow rw chain (904s on v4.36.0) with direct Eq.trans/congrArg steps (~36s total file build)
    • AlgebraicGeometry/ChartTransNonNested/RelativeProj.lean: removed remaining attribute [local implicit_reducible] AlgebraicGeometry.Proj via isIso_app_pushforward_unit_eq
    • Deformation/FormalObject/VersalCriterion.lean: factored isVersal_iff into three private lemmas (kernel time 33× faster)
    • Algebra/Homology/DerivedHomologyLinear.lean: replaced public import Mathlib with 4 targeted Mathlib imports (1,777 jobs, 9.4s wall / 1.10 GB RSS)
    • AlgebraicGeometry/EtaleCohomology/BaseChangeHigher/LadderAssembly.lean: bundled 6 repeated homologySequence row theorems through one opaque triangulated helper (-31% wall, -35% kernel)
    • CategoryTheory/Sites/Cohomology/Cech/RightDerivedSheafToPresheaf.lean: abstracted addEquiv_natIso_naturality and paste_iso_squares_apply (-36% wall)
    • CategoryTheory/Sites/Cohomology/HigherDirectImage/CohomologyPresheafLocallyZero.lean: removed 34 unrelated Mathlib imports (cutting transitive build cone -46%), scoped file-wide respectTransparency false to 6 declarations, and cut kernel isDefEq on factorBCD_clPrecomp and factorCB_homComplexMap
  • Reduced .olean bloat by 10.7 MB combined:
    • AlgebraicGeometry/Flatness/Devissage/Complete/Transport.lean: 8.8 MB → 1.2 MB (-86.4%, 7.3× smaller)
    • AlgebraicGeometry/Flatness/Devissage/Complete/ShrinkingFinalTarget.lean: 3.1 MB → 1.5 MB (-51.6%, 2.1× smaller)
    • Deformation/FormalObject/RepresentableMorphism/FormalObjectEquivalence.lean: 1.5 MB → 78 KB (-95%, 19.7× smaller)

(Note: During the rebase onto v4.36.0 / commit 73a233be0, 12 originally touched files whose v4.35.0 heartbeat/synthInstance workarounds or kernel bottlenecks were already resolved upstream — BoundedAbove, EpiResData, Nagata/Polynomial, TorAmplitude/BaseChange, OnABasisDegreeOne, TensorBilinear, ProjInclusionDegreeSection/Basic, and the 5 AlgebraicGeometry/Spaces/* files — were cleanly dropped.)


Root-Cause Categories

  1. Kernel & elaborator isDefEq unfolding cliffs across algebraic/categorical junctions
    • Unfolding Proj, preadditiveCoyoneda, Subobject.representative, IntermediateField k (PerfectClosure k p), Subalgebra/MvPolynomial SMul, or MilnorPatching tensor/pullback identifications during whnf/isDefEq.
    • Fixed via scoped attribute [local irreducible] / removing local implicit_reducible on Proj, abstracting lemmas over opaque type/category/complex/ring variables, replacing slow goal-scanning rw chains with direct Eq.trans/congrArg, and splitting monolithic proofs into focused private lemmas (Relative, RelativeProperties, Quotients, ChartTransNonNested/RelativeProj, LocallyFreeRank, Reflexive, AssociatedMorphismMap, VersalCriterion, FormalObjectEquivalence, CohomologyPresheafLocallyZero, SpectralSequence/Tor, Smooth/Conormal, BaseChangeFunctor, MonoidalStructure, PurelyInseparableCriterion, TorAmplitude/Composition, LadderAssembly, RightDerivedSheafToPresheaf).
  2. ComplexShape.up ℤ Add ℤ instance mismatch (Int.instAdd vs AddSemigroup.toAdd)
    • Rewriting via Functor.mapHomologicalComplex_obj_d avoids unfolding TleftCochain / singleFunctor (ScalarBaseChange, DerivedChangeOfRings, DerivedExtensionScalars).
  3. Dependent match and unnecessary @[expose] .olean bloat
    • Replacing dependent match with direct .casesOn/.rec eliminates multi-MB match_1 auxiliary terms (Transport, ShrinkingFinalTarget).
    • Dropping @[expose] on FormalObjectEquivalence removes 68 leaked internal ._proof_* declarations from the public .olean.
  4. Excessive imports and obsolete overrides
    • Replacing public import Mathlib (DerivedHomologyLinear), removing 34 unrelated Mathlib imports (CohomologyPresheafLocallyZero), and removing obsolete maxHeartbeats / synthInstance.maxHeartbeats / respectTransparency false overrides (FiniteTypeLocallySurjective, SheafHomLeftExact, InternalHom, DeltaFunctor, ProdDeterminant, DerivedTensorFunctorLargeUniverse, MinimalPrimes, LiftIdempotentsAndModules).

Modified Modules (32 Files)

  • StacksFrontier/Algebra/Category/ModuleCat/Presheaf/InternalHom.lean
  • StacksFrontier/Algebra/Category/ModuleCat/Sheaf/FiniteTypeLocallySurjective.lean
  • StacksFrontier/Algebra/Category/ModuleCat/Sheaf/LocallyFreeRank.lean
  • StacksFrontier/Algebra/Category/ModuleCat/Sheaf/SheafHomLeftExact.lean
  • StacksFrontier/Algebra/Homology/DerivedCategory/RightDerivedFunctorInjective/DeltaFunctor.lean
  • StacksFrontier/Algebra/Homology/DerivedHomologyLinear.lean
  • StacksFrontier/Algebra/Homology/SpectralSequence/Tor.lean
  • StacksFrontier/Algebra/Module/Projective/Determinant/ShortExact/ProdDeterminant.lean
  • StacksFrontier/Algebra/Module/Reflexive.lean
  • StacksFrontier/AlgebraicGeometry/ChartTransNonNested/RelativeProj.lean
  • StacksFrontier/AlgebraicGeometry/EtaleCohomology/BaseChangeHigher/LadderAssembly.lean
  • StacksFrontier/AlgebraicGeometry/Flatness/Devissage/Complete/ShrinkingFinalTarget.lean
  • StacksFrontier/AlgebraicGeometry/Flatness/Devissage/Complete/Transport.lean
  • StacksFrontier/CategoryTheory/Sites/Cohomology/Cech/RightDerivedSheafToPresheaf.lean
  • StacksFrontier/CategoryTheory/Sites/Cohomology/HigherDirectImage/CohomologyPresheafLocallyZero.lean
  • StacksFrontier/Deformation/FormalObject/AssociatedMorphismMap.lean
  • StacksFrontier/Deformation/FormalObject/RepresentableMorphism/FormalObjectEquivalence.lean
  • StacksFrontier/Deformation/FormalObject/VersalCriterion.lean
  • StacksFrontier/Homology/KFlat/ScalarBaseChange.lean
  • StacksFrontier/Homology/Tor/DerivedChangeOfRings.lean
  • StacksFrontier/Homology/Tor/DerivedExtensionScalars.lean
  • StacksFrontier/Homology/Tor/DerivedTensorFunctorLargeUniverse.lean
  • StacksFrontier/Homology/TorAmplitude/Composition.lean
  • StacksFrontier/RingTheory/Branches/MinimalPrimes.lean
  • StacksFrontier/RingTheory/Etale/LiftIdempotentsAndModules.lean
  • StacksFrontier/RingTheory/GeometricallyRegular/PurelyInseparableCriterion.lean
  • StacksFrontier/RingTheory/Localization/Glueing/FormalGlueingEquivalence/BaseChangeFunctor.lean
  • StacksFrontier/RingTheory/Localization/Glueing/FormalGlueingModuleProperties/MonoidalStructure.lean
  • StacksFrontier/RingTheory/MilnorPatching/Quotients.lean
  • StacksFrontier/RingTheory/MilnorPatching/Relative.lean
  • StacksFrontier/RingTheory/MilnorPatching/RelativeProperties.lean
  • StacksFrontier/RingTheory/Smooth/Conormal.lean

Verification (Lean v4.36.0)

  • Full build on v4.36.0: All 32 modified modules compiled cleanly on leanprover/lean4:v4.36.0 with LEAN_NUM_THREADS=2 (LEAN_NUM_THREADS=1 for CohomologyPresheafLocallyZero) — 0 errors, 0 warnings (including linter.style.numericProjections, linter.style.longLine, linter.unusedTactic, and linter.style.maxHeartbeats).
  • API & axioms: Zero user-facing public signature changes; zero sorry/admit; standard axioms [propext, Classical.choice, Quot.sound]; all 32 modules build with default heartbeat limits.

@joesinghaus
Jakob Oesinghaus (joesinghaus) marked this pull request as draft November 28, 2026 13:50
@joesinghaus
Jakob Oesinghaus (joesinghaus) force-pushed the perf/compile-time-and-memory branch 2 times, most recently from a0066e0 to 65dc2f4 Compare November 28, 2026 21:29
@joesinghaus
Jakob Oesinghaus (joesinghaus) marked this pull request as ready for review November 28, 2026 21:31
…StacksFrontier modules

Reduces compile times, peak memory usage, and .olean sizes across 32 StacksFrontier modules (rebased onto Lean v4.36.0 / main) without changing user-facing public declaration signatures:

- Remove all 28 remaining heartbeat overrides in these modules (26 maxHeartbeats -> 0: 2x 8M, 3x 4M, 5x 2M, 6x 1.6M, 1x 1.5M, 8x 1M, 1x 800k; 2 synthInstance.maxHeartbeats -> 0: 1x 1M, 1x 400k), plus 1 maxRecDepth and 4 backward.isDefEq.respectTransparency false overrides, and scope file-wide respectTransparency false in CohomologyPresheafLocallyZero to 6 declarations.
- Eliminate extreme memory/CPU cliffs (MilnorPatching/Relative, LocallyFreeRank stalk_restrictMod_linearEquiv, ChartTransNonNested/RelativeProj, VersalCriterion, LadderAssembly, RightDerivedSheafToPresheaf, CohomologyPresheafLocallyZero with 34 unused imports removed, and DerivedHomologyLinear public import Mathlib -> 4 targeted imports).
- Reduce .olean bloat by 10.7 MB across Transport (-86%), ShrinkingFinalTarget (-52%), and FormalObjectEquivalence (-95%).
@joesinghaus Jakob Oesinghaus (joesinghaus) changed the title perf: optimize compile times, peak memory, and .olean size across 44 StacksFrontier modules perf: optimize compile times, peak memory, and .olean size across 32 StacksFrontier modules Nov 29, 2026
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