Repository navigation
perf: optimize compile times, peak memory, and .olean size across 32 StacksFrontier modules - #27
Open
Jakob Oesinghaus (joesinghaus) wants to merge 1 commit into
Conversation
Jakob Oesinghaus (joesinghaus)
marked this pull request as draft
November 28, 2026 13:50
Jakob Oesinghaus (joesinghaus)
force-pushed
the
perf/compile-time-and-memory
branch
2 times, most recently
from
November 28, 2026 21:29
a0066e0 to
65dc2f4
Compare
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%).
Jakob Oesinghaus (joesinghaus)
force-pushed
the
perf/compile-time-and-memory
branch
from
November 29, 2026 18:54
65dc2f4 to
bd99d67
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR reduces compile times, peak memory usage, and
.oleansizes across 32StacksFrontiermodules (rebased onto Leanv4.36.0/main) without changing any user-facing public declaration signatures.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 removedbackward.isDefEq.respectTransparency false: 4 removed (MinimalPrimes: 1→0,PurelyInseparableCriterion: 3→0), plus file-widerespectTransparency falseinCohomologyPresheafLocallyZero.lean(covering 65 declarations) scoped down to 6 individual declarationsRingTheory/MilnorPatching/Relative.lean: eliminated remainingmaxHeartbeats 8000000onextensionOfScalarsToTensorProductPullback_iso_one_tmulAlgebra/Category/ModuleCat/Sheaf/LocallyFreeRank.lean: eliminatedmaxHeartbeats 4000000onstalk_restrictMod_linearEquivby extractingrestrictStalkRingEquiv_germand replacing the slowrwchain (904s onv4.36.0) with directEq.trans/congrArgsteps (~36s total file build)AlgebraicGeometry/ChartTransNonNested/RelativeProj.lean: removed remainingattribute [local implicit_reducible] AlgebraicGeometry.ProjviaisIso_app_pushforward_unit_eqDeformation/FormalObject/VersalCriterion.lean: factoredisVersal_iffinto three private lemmas (kernel time 33× faster)Algebra/Homology/DerivedHomologyLinear.lean: replacedpublic import Mathlibwith 4 targeted Mathlib imports (1,777 jobs, 9.4s wall / 1.10 GB RSS)AlgebraicGeometry/EtaleCohomology/BaseChangeHigher/LadderAssembly.lean: bundled 6 repeatedhomologySequencerow theorems through one opaque triangulated helper (-31% wall, -35% kernel)CategoryTheory/Sites/Cohomology/Cech/RightDerivedSheafToPresheaf.lean: abstractedaddEquiv_natIso_naturalityandpaste_iso_squares_apply(-36% wall)CategoryTheory/Sites/Cohomology/HigherDirectImage/CohomologyPresheafLocallyZero.lean: removed 34 unrelated Mathlib imports (cutting transitive build cone -46%), scoped file-widerespectTransparency falseto 6 declarations, and cut kernelisDefEqonfactorBCD_clPrecompandfactorCB_homComplexMap.oleanbloat 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/ commit73a233be0, 12 originally touched files whosev4.35.0heartbeat/synthInstance workarounds or kernel bottlenecks were already resolved upstream —BoundedAbove,EpiResData,Nagata/Polynomial,TorAmplitude/BaseChange,OnABasisDegreeOne,TensorBilinear,ProjInclusionDegreeSection/Basic, and the 5AlgebraicGeometry/Spaces/*files — were cleanly dropped.)Root-Cause Categories
isDefEqunfolding cliffs across algebraic/categorical junctionsProj,preadditiveCoyoneda,Subobject.representative,IntermediateField k (PerfectClosure k p),Subalgebra/MvPolynomialSMul, orMilnorPatchingtensor/pullback identifications duringwhnf/isDefEq.attribute [local irreducible]/ removinglocal implicit_reducibleonProj, abstracting lemmas over opaque type/category/complex/ring variables, replacing slow goal-scanningrwchains with directEq.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).ComplexShape.up ℤAdd ℤinstance mismatch (Int.instAddvsAddSemigroup.toAdd)Functor.mapHomologicalComplex_obj_davoids unfoldingTleftCochain/singleFunctor(ScalarBaseChange,DerivedChangeOfRings,DerivedExtensionScalars).matchand unnecessary@[expose].oleanbloatmatchwith direct.casesOn/.receliminates multi-MBmatch_1auxiliary terms (Transport,ShrinkingFinalTarget).@[expose]onFormalObjectEquivalenceremoves 68 leaked internal._proof_*declarations from the public.olean.public import Mathlib(DerivedHomologyLinear), removing 34 unrelated Mathlib imports (CohomologyPresheafLocallyZero), and removing obsoletemaxHeartbeats/synthInstance.maxHeartbeats/respectTransparency falseoverrides (FiniteTypeLocallySurjective,SheafHomLeftExact,InternalHom,DeltaFunctor,ProdDeterminant,DerivedTensorFunctorLargeUniverse,MinimalPrimes,LiftIdempotentsAndModules).Modified Modules (32 Files)
StacksFrontier/Algebra/Category/ModuleCat/Presheaf/InternalHom.leanStacksFrontier/Algebra/Category/ModuleCat/Sheaf/FiniteTypeLocallySurjective.leanStacksFrontier/Algebra/Category/ModuleCat/Sheaf/LocallyFreeRank.leanStacksFrontier/Algebra/Category/ModuleCat/Sheaf/SheafHomLeftExact.leanStacksFrontier/Algebra/Homology/DerivedCategory/RightDerivedFunctorInjective/DeltaFunctor.leanStacksFrontier/Algebra/Homology/DerivedHomologyLinear.leanStacksFrontier/Algebra/Homology/SpectralSequence/Tor.leanStacksFrontier/Algebra/Module/Projective/Determinant/ShortExact/ProdDeterminant.leanStacksFrontier/Algebra/Module/Reflexive.leanStacksFrontier/AlgebraicGeometry/ChartTransNonNested/RelativeProj.leanStacksFrontier/AlgebraicGeometry/EtaleCohomology/BaseChangeHigher/LadderAssembly.leanStacksFrontier/AlgebraicGeometry/Flatness/Devissage/Complete/ShrinkingFinalTarget.leanStacksFrontier/AlgebraicGeometry/Flatness/Devissage/Complete/Transport.leanStacksFrontier/CategoryTheory/Sites/Cohomology/Cech/RightDerivedSheafToPresheaf.leanStacksFrontier/CategoryTheory/Sites/Cohomology/HigherDirectImage/CohomologyPresheafLocallyZero.leanStacksFrontier/Deformation/FormalObject/AssociatedMorphismMap.leanStacksFrontier/Deformation/FormalObject/RepresentableMorphism/FormalObjectEquivalence.leanStacksFrontier/Deformation/FormalObject/VersalCriterion.leanStacksFrontier/Homology/KFlat/ScalarBaseChange.leanStacksFrontier/Homology/Tor/DerivedChangeOfRings.leanStacksFrontier/Homology/Tor/DerivedExtensionScalars.leanStacksFrontier/Homology/Tor/DerivedTensorFunctorLargeUniverse.leanStacksFrontier/Homology/TorAmplitude/Composition.leanStacksFrontier/RingTheory/Branches/MinimalPrimes.leanStacksFrontier/RingTheory/Etale/LiftIdempotentsAndModules.leanStacksFrontier/RingTheory/GeometricallyRegular/PurelyInseparableCriterion.leanStacksFrontier/RingTheory/Localization/Glueing/FormalGlueingEquivalence/BaseChangeFunctor.leanStacksFrontier/RingTheory/Localization/Glueing/FormalGlueingModuleProperties/MonoidalStructure.leanStacksFrontier/RingTheory/MilnorPatching/Quotients.leanStacksFrontier/RingTheory/MilnorPatching/Relative.leanStacksFrontier/RingTheory/MilnorPatching/RelativeProperties.leanStacksFrontier/RingTheory/Smooth/Conormal.leanVerification (Lean
v4.36.0)v4.36.0: All 32 modified modules compiled cleanly onleanprover/lean4:v4.36.0withLEAN_NUM_THREADS=2(LEAN_NUM_THREADS=1forCohomologyPresheafLocallyZero) — 0 errors, 0 warnings (includinglinter.style.numericProjections,linter.style.longLine,linter.unusedTactic, andlinter.style.maxHeartbeats).sorry/admit; standard axioms[propext, Classical.choice, Quot.sound]; all 32 modules build with default heartbeat limits.