Skip to content

perf(DavisKahan): narrow proof imports and simplify operator estimates - #823

Merged
Vilin97 merged 1 commit into
mainfrom
codex/daily-optimize-20261114
Nov 15, 2026
Merged

Vilin97 merged 1 commit into
mainfrom
codex/daily-optimize-20261114

Conversation

@Vilin97

@Vilin97 Vilin97 commented Nov 15, 2026

Copy link
Copy Markdown
Collaborator

Ready for review: reduce DavisKahan compilation costs while preserving every owned declaration.

Scope and changes

DavisKahan is a completed project with 1,082 modules and about 302,000 lines of Lean. The reference clean build took 43:31.32, with Sharpness the slowest module at 189 seconds and BeamSection9 the largest compiler process by sampled RSS. Its broad tactic imports and foundational proof dependencies made it a useful single-project target.

  • Replace broad Mathlib.Tactic imports with explicit private tactic imports, retaining metaprogram dependencies with shake: keep.
  • Reclassify 75 proof dependencies in 35 foundational modules as private or meta imports. Preserve required public providers, add explicit imports in consumers, and retain all owned project reexports. Lake's resolved import artifact map for Sharpness falls from 3,174 to 2,940 modules. The full target’s resolved map falls from 4,964 to 4,586 entries.
  • Replace nonlinear search with direct order, norm and power lemmas, or explicit polynomial certificates. Restrict remaining arithmetic search to the antecedents it uses.
  • Reuse the existing Cauchy–Schwarz helper and the existing antilipschitz injection argument. Prove the planar singular-value calculation by equality of two 2×2 Gram matrices and the existing lower-left matrix lemma.

Semantic invariant

Base: 503d6a74ee9be787839d823d271a0673e1283b1d; head: 6fdd2a50f060c828025ca9bedaff64b445505c61.

Before editing, save the complete compiled baseline, source snapshot and a Lean environment manifest. Compare the final environment exactly, rather than up to definitional equality. A second audit reads each module's own ModuleData.constants and its public export records, so repeated names of Lean-generated helpers cannot mask a difference in another module.

Both audits pass for all 21,500 entries: 17,385 theorem entries, 3,569 definitions, 179 inductives, 188 constructors and 179 recursors. There are zero changed types, universe lists, non-theorem values, safety/reducibility/kernel metadata, export records, removed declarations, additions or shadowed names. Only theorem proof bodies are excluded from equality; 179 informational proof hashes differ. Parsed source signatures also match exactly across all 107 changed files. No definition, instance, notation, namespace or theorem statement is edited.

The comparison encodes complete Lean expressions as DAGs, canonicalizes the JSON, and compares it exactly using lossless deterministic compression. It does not infer semantic preservation from source text or proof hashes. The pre-edit environment audit and the module-local audit both pass. The latter reconstructs the baseline from the original compiled artifacts retained before editing.

Raw module manifest SHA-256:

  • Base: 98abb4cb2d0cc01208498064bde2ef9462edafdc5f23e3336ff4f29c7a694206
  • Head: 8e61fce162c545b61b8d277c82a4fe32c6a223ad29c9b6311718880528245218

Measurements

Metric Baseline Optimized Reduction
Clean target wall time 2,611.32 s (43:31.32) 2,311.04 s (38:31.04) 11.50%
Largest compiler process RSS 2,064,304 KiB 1,850,448 KiB 10.36%
Aggregate user + system CPU time 6,030.20 s 6,027.78 s 0.04%

Both measurements run on the same Azure VM, rebuilding all 1,082 owned modules from absent project artifacts while retaining the pinned prebuilt dependencies:

LEAN_NUM_THREADS=6 /usr/bin/time -v -o timing.txt taskset -c 0-5 \
  python3 python/lean_pool/build_time_limits.py watch -- \
  lake build LeanPool.DavisKahan.Imports

Only this isolated worktree's DavisKahan artifacts under .lake/build/lib/lean/LeanPool/ and .lake/build/ir/LeanPool/ are removed. GNU time's maximum RSS is the largest process in the build, not the sum of concurrent processes. Module wall times are taken from the Lake logs.

The initial reference build started at e5baf4dfa2e55f1dc4bb25558f1432209fc41d00. Intervening main commits were checked to leave the project, pinned dependencies, Lake settings and compiler plugin byte-identical. Lean remains 4.35.0, with Mathlib 56a005855ea17e0b0958f73ec801ae140b0a1679; no version or gate changes are included.

Validation

  • Warning-free lake build LeanPool.DavisKahan.Imports, with the repository watchdog and compiler plugin.
  • Exact environment and module-local declaration/export comparisons described above.
  • Mathlib's slow declaration linters via scripts/ci/lint-project.lean, supplied all 1,082 owned modules: 21,403 unique environment declarations pass.
  • lake exe lint-style LeanPool.DavisKahan.Imports.
  • Unchanged repository quality routines scoped to the selected project: headers, forbidden text, sizes, registered declarations, allowed axioms, option/backdoor audit, and configuration/no-waiver checks.
  • lake exe mk_all --module --check and git diff --check. No generated index changes are required.
  • python3 python/lean_pool/build_time_limits.py check --log head-cold.log --base 503d6a74ee9be787839d823d271a0673e1283b1d: all 107 changed modules covered, maximum 205 s, zero 600-second violations.

Limits

This is a controlled artifact-clean comparison on a busy shared VM. CPU scheduling and the OS page cache are not isolated or reset. Exploratory replays used a separate CPU during the baseline, and the VM hosts unrelated work. Aggregate CPU time is essentially unchanged; wall-time gains are observations rather than a guaranteed speedup on other machines. The baseline also includes the small one-time compiler-plugin build; the optimized run reuses it. External Mathlib proof dependencies are intentionally no longer reexported through every intermediate module; consumers now import their providers explicitly. Owned declarations and owned reexports are preserved by the audits above.

All 3,249 checked .olean/private/server artifact files and associated hashes are byte-identical between the validated build and the fresh measured build. All 107 final source hashes also match.

Sharpness had clean-run wall times of 189 →205 s. To investigate that result, replay the saved base and final sources/dependencies in base/head/head/base order, one compiler at a time, with the same affinity, six threads, plugin/options, and normal .olean/.ilean/C output. All four replays pass. Median CPU time falls 145.315 →138.735 s (4.53%), with median RSS 1,914,656 →1,848,962 KiB (3.43%). This supports the inference that the isolated file-wall regression reflects scheduling variation.

The one-second sampler saw a sum of compiler RSS of 10,069,244 →9,800,964 KiB (2.66% lower). This proxy counts shared mapped pages repeatedly; the baseline sampler also began after early modules. It is not a measurement of total physical VM memory.

Daily documentation publication is asynchronous and is not used as a merge gate. This PR is left open for the applicable validation workflows and independent review; it is not merged automatically.

@greptile-apps

greptile-apps Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Advisory cross-file review against Lean Pool's supervisory rubric. This is not by itself a significance, source-verification, or merge verdict.

RetriggerView in Greptile

[Medium impact] No blocking issue was found in this import and proof refactor.

Summary

This refactor narrows imports and replaces broad arithmetic searches with focused proofs.

  • DavisKahan modules load narrower proof and math imports.
  • Proofs use focused arithmetic and direct lemmas to reduce search work.

All supplied changes and the omitted diff were reviewed. Builds, compiled-environment audits, and timing measurements were not rerun. External source and license evidence was not independently reverified; this PR leaves those records unchanged.

Vilin97 explicitly identifies the removal of external Mathlib reexports as intentional. No separate loss of owned declarations was established. Vilin97 also acknowledges the clean-run wall-time increase for Sharpness.lean and reports controlled follow-up measurements; the supplied evidence does not establish a regression caused by the rewrite.

Reviews (1) · Last reviewed commit: "perf(DavisKahan): narrow proof imports a..." · Reviewed by Greptile

@github-actions

Copy link
Copy Markdown
Contributor

Proof profile (new / modified Lean files)

Statement changes

✅ No statements changed — all 2,240 tracked declarations across 107 modified files kept their type; only proofs / definition bodies changed.

Statements are compared textually against the merge base (comments and whitespace ignored; by proof terms embedded in a type are treated as proof-irrelevant), the same method as physlib's /check-golf. Anonymous instances and examples are not tracked.

Compile cost of modified files — base → head

Heartbeats: 15,694,051 → 14,882,837 (-811,214, -5.2%). Commands: 5,178 → 5,178.

Per-file wall sum: 2836.4 s → 1558.9 s (-45.0%). Wall clock is measured under parallel load and is noisy; heartbeats are deterministic and are the regression signal.

Files: 102 compared — 31 cheaper, 0 costlier, 71 within noise (threshold: |Δ heartbeats| ≥ 1,000 and ≥ 1%).

Both sides are elaborated against the merge-base build of the pool — sound when only proofs and definition bodies change; a file whose statements changed may fail there and is flagged ⚠. Heartbeats come from disjoint root command traces with trace.profiler.useHeartbeats and synchronous elaboration, converted to maxHeartbeats units. Failed measurements are not classified as cheaper or costlier. Δ lines counts added/deleted lines from this PR diff.

File Δ lines HB base HB head Δ HB Δ HB % Wall base (s) Wall head (s)
LeanPool/DavisKahan/ForTauCeti/Analysis/InnerProductSpace/CoerciveUnit.lean +71/-78 225,932 109,828 -116,105 -51.4% 44.29 10.87
LeanPool/DavisKahan/ForTauCeti/Analysis/InnerProductSpace/DoubleAngle/Vector.lean +4/-4 220,955 111,590 -109,365 -49.5% 38.13 15.70
LeanPool/DavisKahan/DavisKahan/FiniteDimensional/DoubleAngle/TanTheta.lean +5/-5 798,646 711,417 -87,229 -10.9% 90.66 53.00
LeanPool/DavisKahan/DavisKahan/Sylvester/ShiftedInverse.lean +6/-6 328,503 257,129 -71,374 -21.7% 30.21 18.27
LeanPool/DavisKahan/DavisKahan/Sources/DavisKahan1970/Section9/IndividualAngles.lean +9/-9 117,119 53,339 -63,781 -54.5% 18.47 5.14
LeanPool/DavisKahan/ForTauCeti/Analysis/InnerProductSpace/Spectral/GapProjection.lean +8/-6 235,693 184,516 -51,177 -21.7% 40.86 19.05
LeanPool/DavisKahan/ForTauCeti/Analysis/Normed/Operator/SylvesterBoundedInverse.lean +3/-3 374,729 335,511 -39,218 -10.5% 64.80 37.04
LeanPool/DavisKahan/ForTauCeti/Analysis/InnerProductSpace/OrthogonalGluing.lean +2/-6 367,567 333,510 -34,057 -9.3% 41.18 20.82
LeanPool/DavisKahan/DavisKahan/Geometry/Angle/OperatorAngleComplex.lean +6/-6 471,115 440,318 -30,797 -6.5% 74.16 47.44
LeanPool/DavisKahan/ForTauCeti/Analysis/Fourier/Poisson/CauchyLattice.lean +9/-9 76,929 47,390 -29,539 -38.4% 13.36 6.73
LeanPool/DavisKahan/ForTauCeti/Analysis/SpecialFunctions/Sqrt.lean +6/-6 70,126 43,113 -27,012 -38.5% 12.59 6.38
LeanPool/DavisKahan/ForTauCeti/Analysis/InnerProductSpace/LyapunovPositivity.lean +4/-4 205,328 182,957 -22,371 -10.9% 45.18 17.32
LeanPool/DavisKahan/ForTauCeti/Analysis/InnerProductSpace/Spectral/Cutoff.lean +7/-7 370,298 354,664 -15,634 -4.2% 58.35 42.77
LeanPool/DavisKahan/ForTauCeti/Analysis/InnerProductSpace/BorelCalculus/Operator.lean +1/-1 196,604 181,262 -15,343 -7.8% 39.52 19.14
LeanPool/DavisKahan/DavisKahan/Sources/DavisKahan1970/Section9/TrialSubspace.lean +6/-8 71,186 58,986 -12,200 -17.1% 11.60 5.56
LeanPool/DavisKahan/DavisKahan/Sources/DavisKahan1970/Section9/NumericalBounds.lean +33/-40 102,622 92,816 -9,807 -9.6% 11.10 7.49
LeanPool/DavisKahan/ForTauCeti/Analysis/InnerProductSpace/PrincipalAngles.lean +1/-1 390,362 381,059 -9,303 -2.4% 73.89 34.07
LeanPool/DavisKahan/ForTauCeti/Analysis/InnerProductSpace/SphericalPythagoras.lean +4/-4 76,266 68,347 -7,919 -10.4% 18.03 8.36
LeanPool/DavisKahan/ForTauCeti/Analysis/SpecialFunctions/Integral/RationalQuadratic.lean +16/-14 111,111 103,739 -7,371 -6.6% 27.90 15.18
LeanPool/DavisKahan/ForTauCeti/Analysis/InnerProductSpace/LinearPMap/SpectralSupport.lean +3/-3 24,617 18,997 -5,620 -22.8% 8.39 4.57
LeanPool/DavisKahan/DavisKahan/Sources/DavisKahan1970/Section9/SchurComplement.lean +3/-3 59,429 54,203 -5,226 -8.8% 14.12 6.85
LeanPool/DavisKahan/ForTauCeti/Analysis/InnerProductSpace/KyFan.lean +3/-3 245,187 240,295 -4,892 -2.0% 48.48 21.68
LeanPool/DavisKahan/DavisKahan/Riccati/UnboundedAdjointRiccati.lean +2/-2 716,315 711,820 -4,495 -0.6% 90.18 48.57
LeanPool/DavisKahan/DavisKahan/Sources/DavisKahan1970/Section9/DomainLimitation.lean +10/-10 60,705 56,362 -4,343 -7.2% 15.73 8.80
LeanPool/DavisKahan/ForTauCeti/Analysis/InnerProductSpace/Polar/Decomposition.lean +3/-3 146,693 143,446 -3,247 -2.2% 26.28 18.89
LeanPool/DavisKahan/ForTauCeti/Analysis/RCLike/ScalarTransport.lean +6/-6 158,459 155,240 -3,218 -2.0% 31.12 18.20
LeanPool/DavisKahan/ForTauCeti/Analysis/OperatorIdeal/ApproximationNumber/FiniteValueSeparation.lean +3/-3 10,153 7,234 -2,919 -28.7% 4.81 2.84
LeanPool/DavisKahan/ForTauCeti/Analysis/InnerProductSpace/OperatorRealAlgebra.lean +5/-4 19,259 16,790 -2,468 -12.8% 5.32 4.00
LeanPool/DavisKahan/DavisKahan/Sources/DavisKahan1970/Section9/FreeBeamRootExclusion.lean +3/-3 34,148 31,719 -2,429 -7.1% 11.33 5.91
LeanPool/DavisKahan/ForTauCeti/Analysis/InnerProductSpace/BorelCalculus/Multiplicative.lean +2/-2 266,271 264,039 -2,232 -0.8% 41.00 18.87
LeanPool/DavisKahan/ForTauCeti/Analysis/Fourier/ExponentialAbs.lean +6/-5 43,762 41,771 -1,992 -4.6% 12.87 6.50
LeanPool/DavisKahan/Palomar/DKSectionTwo/SolutionPrelude.lean +3/-3 103,351 102,140 -1,211 -1.2% 15.60 9.59
LeanPool/DavisKahan/ForTauCeti/Analysis/SpecialFunctions/TanArcsin.lean +4/-4 8,707 7,578 -1,129 -13.0% 4.73 3.47
LeanPool/DavisKahan/DavisKahan/SpectralTheory/FormMethod/TraceKernelModel.lean +0/-2 47,040 46,097 -943 -2.0% 9.70 4.06
LeanPool/DavisKahan/ForTauCeti/Analysis/InnerProductSpace/Rosenblum.lean +2/-2 116,770 115,832 -939 -0.8% 24.31 16.13
LeanPool/DavisKahan/ForTauCeti/Analysis/InnerProductSpace/LinearPMap/SelfAdjointResolvent.lean +2/-2 150,962 150,056 -906 -0.6% 29.87 20.34
LeanPool/DavisKahan/ForTauCeti/Analysis/InnerProductSpace/LinearPMap/SpectralGrid.lean +2/-2 23,716 23,110 -606 -2.6% 9.01 5.24
LeanPool/DavisKahan/ForTauCeti/Analysis/InnerProductSpace/NearIsometry.lean +2/-2 109,004 108,471 -533 -0.5% 24.60 15.05
LeanPool/DavisKahan/DavisKahan/Analysis/FourthOrderODE/ComplexGreenIdentity.lean +1/-2 16,044 15,541 -503 -3.1% 12.33 8.04
LeanPool/DavisKahan/DavisKahan/SpectralTheory/FormMethod/PositiveSurjectiveCriterion.lean +3/-2 29,781 29,463 -319 -1.1% 10.47 5.53
LeanPool/DavisKahan/ForTauCeti/Analysis/InnerProductSpace/EigenvalueChange.lean +2/-2 67,261 66,956 -305 -0.5% 18.32 6.54
LeanPool/DavisKahan/DavisKahan/Sources/DavisKahan1970/Section9/FreeBeamCharacteristic.lean +6/-2 25,900 25,619 -281 -1.1% 9.93 5.20
LeanPool/DavisKahan/ForTauCeti/Analysis/InnerProductSpace/Projection/Gap.lean +1/-1 239,917 239,700 -217 -0.1% 43.74 22.10
LeanPool/DavisKahan/ForTauCeti/Analysis/InnerProductSpace/Sylvester/Bound.lean +2/-1 348,807 348,610 -197 -0.1% 44.43 27.85
LeanPool/DavisKahan/ForTauCeti/Analysis/InnerProductSpace/Complexification/FunctionalCalculus.lean +9/-6 276,448 276,263 -185 -0.1% 32.20 23.42
LeanPool/DavisKahan/DavisKahan/Analysis/FourthOrderODE/SmoothGreenIdentity.lean +2/-2 9,687 9,522 -164 -1.7% 11.02 6.78
LeanPool/DavisKahan/ForTauCeti/Analysis/Fourier/HaagerupZsido/Integrability.lean +7/-4 20,943 20,817 -126 -0.6% 5.93 4.78
LeanPool/DavisKahan/ForTauCeti/Analysis/InnerProductSpace/Sylvester/Internal/ReciprocalMultiplier.lean +2/-0 132,811 132,708 -104 -0.1% 29.32 16.35
LeanPool/DavisKahan/DavisKahan/SpectralTheory/PartialMap/Complexification.lean +3/-3 439,004 439,056 +52 +0.0% 66.75 32.52
LeanPool/DavisKahan/ForTauCeti/Analysis/InnerProductSpace/Sylvester/Internal/ReciprocalMultiplier/Fourier.lean +8/-4 130,920 130,971 +51 +0.0% 25.88 13.83
… +52 more files, each with a smaller move (≤ 45 HB); full table in the run's step summary
Total +432/-405 15,694,051 14,882,837 -811,214 -5.2% 2836.4 1558.9

New files — absolute profile

Total heartbeats: 680,476 maxHeartbeats units across 2 valid files (78 added LOC).

Sum of lean --profile: — across 0 valid files. Import-excluded time: —.

Count-heartbeats wall-clock total: 58.28 s. Repeated import cost inside lean --profile: —.

Heartbeat values sum disjoint root command traces with trace.profiler.useHeartbeats and synchronous elaboration, converted from raw allocations to maxHeartbeats units by dividing by 1000. They include command elaboration and kernel checking, exclude imports, and include profiler overhead; they are not comparable to the deprecated linter's totals. Per-file wall clocks are measured under parallel load and are noisier than heartbeats.

LOC counts added lines in the profiled Lean files from this PR diff.

File LOC Heartbeats (maxHB) Count wall (s) lean --profile (s) Without import (s) Import (s) Commands Errors
LeanPool/DavisKahan/ForTauCeti/Analysis/InnerProductSpace/DoubleAngle/UnboundedPole.lean 8 487,407 40.91 — — — 53 0
LeanPool/DavisKahan/DavisKahan/Sources/DavisKahan1970/Section9/WeinbergerComparison.lean 34 193,069 17.37 — — — 43 0
LeanPool/DavisKahan/DavisKahan/FiniteDimensional/Sharpness.lean 22 — — — — — 183 1
LeanPool/DavisKahan/ForTauCeti/Analysis/InnerProductSpace/Polar/SelfAdjointCompletion.lean 13 — — — — — 93 1
LeanPool/DavisKahan/ForTauCeti/Analysis/InnerProductSpace/TwoDimensionalSingularValues.lean 1 — — — — — 24 1
Total 78 680,476 58.28 — — — 396 3

Aggregate phase totals

Phase Time
Unavailable —

Advisory only — never blocks merge. Full log uploaded as the proof-profile artifact.

@Vilin97 Vilin97 left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve — source review of 6fdd2a50f060c828025ca9bedaff64b445505c61; required CI is still running.

The narrower tactic imports and explicit arithmetic hypotheses make the proof dependencies easier to follow. The operator arguments preserve their structure: coercivity still supplies injectivity and closed range, inverse estimates retain their positivity and nonzero-denominator guards, and the sharpness calculation uses equality of the two explicit Gram matrices with existing singular-value lemmas. Reusing the existing Cauchy–Schwarz helper improves maintenance without adding an abstraction layer.

  • Assessment: maintainability improved; arithmetic proofs more explicit; integration risk medium because imports change across 107 existing files. No blocking source findings.
  • Scope: all 107 files remain within DavisKahan. The written declaration contracts and ambient assumptions are preserved; external Mathlib reexports are intentionally narrowed. Hosted CI must still confirm elaboration and downstream integration.
  • Validation: proper Lean Action CI 43662433374/a1 is building the project. Author-reported private audits and timings are not validation credit for this review.

This independent refactor review supplies the source verdict. I will enqueue the accepted head through normal protections once its applicable required checks pass and current-main readiness is verified.

@Vilin97

Vilin97 commented Nov 15, 2026

Copy link
Copy Markdown
Collaborator Author

🤖 LLM review — refactor (gpt-6.1-sol)

Reviewed head: 6fdd2a50f060c828025ca9bedaff64b445505c61

Verdict: ✅ approve

This refactor narrows proof imports, restricts arithmetic search to explicit inputs, and reuses existing operator lemmas. The larger rewrites retain named intermediate bounds and readable proof structure; public project-import edges remain unchanged. The supplied profile reports 5.2% fewer heartbeats across compared files. Builds and compiled-environment audits were not rerun because this checkout lacks dependency artifacts.

Aspect Value
Scope import narrowing and targeted proof rewrites
Introduces tech debt ✅ no
Maintainability ✅ improved
Brittleness ✅ more_robust
Risk ✅ low

Explicit arithmetic dependencies and shared helper arguments make these proofs easier to repair and maintain, with no actionable regression identified.


Tokens: 1,536,090 in / 8,414 out · Tier: codex-subscription · Effort: xhigh · Billing: Codex subscription quota (no API credits) · Estimated cost: $6.2706 (Standard API equivalent; uncached input) (long-context rate)
Automated review against .github/REFACTOR_REVIEW_RULES.md. Disagree? Reply on the PR; rules can be updated in a PR of their own.

@Vilin97
Vilin97 added this pull request to the merge queue Nov 15, 2026
Merged via the queue into main with commit 595ff87 Nov 15, 2026
28 checks passed
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