Skip to content

perf(DomainTheory): narrow imports and factor repeated proofs - #720

Open
Vilin97 wants to merge 1 commit into
mainfrom
codex/daily-optimize-domain-theory-20261026
Open

Vilin97 wants to merge 1 commit into
mainfrom
codex/daily-optimize-domain-theory-20261026

Conversation

@Vilin97

@Vilin97 Vilin97 commented Oct 26, 2026

Copy link
Copy Markdown
Collaborator

Summary

Optimize the completed DomainTheory project against current main (edbe5bd56f476cc2965564676b66199f281ab714). The change narrows the project entry module to terminal public imports that retain the complete API and factors repeated proof calculations across the neighborhood and continuous-lattice developments. It touches only LeanPool/DomainTheory.lean and files under LeanPool/DomainTheory/.

Semantic invariant audit

I generated a base/head declaration manifest by importing LeanPool.DomainTheory in Lean and recording each project declaration’s name, kind, safety level, universe parameters, fully elaborated type hash, and value hash. The base manifest has 6,783 declarations; the optimized head has 7,380. Every pre-existing declaration signature is present at the head (zero missing signatures). The 597 additions are support declarations introduced by proof factoring. No pre-existing def, opaque, inductive, constructor, recursor, quotient, or axiom value hash changed; theorem proof hashes changed only where the optimization rewrote proofs. No existing public statement or definition was changed.

Measurements

Both measurements used /usr/bin/time -v lake build LeanPool.DomainTheory with the workspace build/ and ir/ directories cleared between runs, the same base/head toolchain, and warm dependency caches. Each build completed 1,467 jobs.

  • Base edbe5bd56f476cc2965564676b66199f281ab714: 1:13.40 wall, 1,028,464 KB peak RSS.
  • Head 592258de68f6a2d502fed99a883ae5fca94082b1: 1:05.40 wall, 1,009,804 KB peak RSS.
  • Result: 10.9% lower wall time and 1.8% lower peak RSS.

Validation

  • lake build LeanPool.DomainTheory
  • lake exe mk_all --module --check
  • lake exe runLinter LeanPool.DomainTheory
  • lake exe lint-style LeanPool.DomainTheory
  • cd python && uv run python -m lean_pool.quality --repo .. --static-only

The full-pool quality environment audit is left to CI because this isolated cycle builds only the selected project.

@greptile-apps

greptile-apps Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

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] The changes reach the full DomainTheory project and its build workflow.

No blocking code issue was found; the expanded proof in Example14.lean has a non-blocking maintenance concern.

Findings

  1. P2 Repeated branches increase upkeep ▶

Summary

Narrows DomainTheory imports and reuses shared proofs for directed suprema, inclusion relations, and projection pairs.

  • DomainTheory keeps its API while shared proof steps reduce build work.

Reviews (1) · Last reviewed commit: "Optimize DomainTheory imports and repeat..." · Reviewed by Greptile

Comment on lines +434 to +440
· exact Or.inl (master_inter _)
· exact Or.inr (Or.inl (master_inter _))
· exact Or.inr (Or.inr (Or.inl (master_inter _)))
· exact Or.inr (Or.inr (Or.inr (Or.inl (master_inter _))))
· exact Or.inr (Or.inr (Or.inr (Or.inr (Or.inl (master_inter _)))))
· exact Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inl (master_inter _))))))
· exact Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inl (master_inter _)))))))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Repeated branches increase upkeep

inter_eq replaces one shared proof with 49 hand-written branches, each choosing a position in the same eight-way conclusion. Changes to the cases or conclusion order now require edits across that table. The existing intersection lemmas still supply every calculation. Use a shared finishing step instead of repeating the nested Or.inr constructors.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@github-actions

Copy link
Copy Markdown
Contributor

Proof profile (new / modified Lean files)

Statement changes

✅ No statements changed — all 3,516 tracked declarations across 127 modified files kept their type; only proofs / definition bodies changed.

Also: 4 declarations added, 0 removed. A reorganization moves declarations between files, which shows up here as an add in one file and a remove in another.

➕ Declarations added (4)
  • Domain.ContinuousLattice.ScottMap.iSup_apply — LeanPool/DomainTheory/ContinuousLattice/FunctionSpaces.lean
  • Domain.ContinuousLattice.ScottMap.map_iSup_of_directed — LeanPool/DomainTheory/ContinuousLattice/FunctionSpaces.lean
  • Domain.Neighborhood.ApproximableMap.relation_iff_subset_of_diagonal — LeanPool/DomainTheory/Neighborhood/Approximable.lean
  • Domain.Neighborhood.Exercise619.Subsystem.projection_eq_of_projection_pair — LeanPool/DomainTheory/Neighborhood/Exercise623.lean

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: 1,181,799 → 938,674 (-243,125, -20.6%). Commands: 4,885 → 4,888.

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

Files: 120 compared — 29 cheaper, 0 costlier, 91 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/DomainTheory/Neighborhood/Example14.lean +250/-153 64,442 15,711 -48,732 -75.6% 15.50 5.87
LeanPool/DomainTheory/Neighborhood/FunctionSpace.lean +24/-19 53,563 23,075 -30,487 -56.9% 14.21 7.41
LeanPool/DomainTheory/Neighborhood/Theorem75.lean +40/-36 69,492 42,301 -27,191 -39.1% 13.14 8.83
LeanPool/DomainTheory/ContinuousLattice/FunctionSpaces.lean +55/-27 96,625 74,294 -22,330 -23.1% 22.82 20.37
LeanPool/DomainTheory/Neighborhood/Recursive.lean +17/-11 52,866 41,875 -10,991 -20.8% 11.07 9.94
LeanPool/DomainTheory/Neighborhood/Theorem614.lean +5/-3 25,481 15,309 -10,171 -39.9% 7.35 5.10
LeanPool/DomainTheory/Neighborhood/Theorem616.lean +3/-7 17,105 7,780 -9,325 -54.5% 4.36 3.92
LeanPool/DomainTheory/Neighborhood/Exercise328.lean +8/-9 13,629 6,170 -7,459 -54.7% 3.10 2.56
LeanPool/DomainTheory/Neighborhood/Exercise516Overlap.lean +4/-9 29,227 22,331 -6,896 -23.6% 7.73 5.74
LeanPool/DomainTheory/Neighborhood/Proposition77.lean +20/-10 52,520 47,184 -5,336 -10.2% 14.18 12.36
LeanPool/DomainTheory/Neighborhood/Exercise510.lean +17/-16 25,577 20,617 -4,959 -19.4% 8.40 6.13
LeanPool/DomainTheory/ContinuousLattice/Injective.lean +3/-3 7,376 2,762 -4,614 -62.5% 4.42 5.24
LeanPool/DomainTheory/Neighborhood/Example62.lean +11/-7 11,270 6,947 -4,323 -38.4% 5.15 3.83
LeanPool/DomainTheory/Neighborhood/Example62C.lean +18/-16 52,400 48,234 -4,166 -8.0% 13.47 12.38
LeanPool/DomainTheory/Neighborhood/Exercise118.lean +27/-13 10,879 7,316 -3,564 -32.8% 4.26 3.32
LeanPool/DomainTheory/Neighborhood/Exercise317.lean +14/-16 13,579 10,301 -3,278 -24.1% 4.79 4.15
LeanPool/DomainTheory/ContinuousLattice/Constructions.lean +8/-7 20,922 18,029 -2,893 -13.8% 9.64 8.57
LeanPool/DomainTheory/Neighborhood/Example62A.lean +8/-6 14,484 11,601 -2,882 -19.9% 5.35 4.35
LeanPool/DomainTheory/ContinuousLattice/ScottMaps.lean +6/-6 11,938 9,453 -2,485 -20.8% 3.96 4.65
LeanPool/DomainTheory/Neighborhood/Exercise629.lean +9/-9 14,386 12,300 -2,086 -14.5% 6.08 5.09
LeanPool/DomainTheory/Neighborhood/Approximable.lean +13/-2 11,504 9,519 -1,985 -17.3% 5.01 3.16
LeanPool/DomainTheory/Neighborhood/Exercise115.lean +20/-18 5,918 4,024 -1,894 -32.0% 3.20 3.00
LeanPool/DomainTheory/Neighborhood/Exercise222.lean +3/-6 12,350 10,528 -1,822 -14.8% 3.97 3.67
LeanPool/DomainTheory/Neighborhood/Example13.lean +27/-27 4,911 3,125 -1,786 -36.4% 3.16 2.47
LeanPool/DomainTheory/Neighborhood/Example12.lean +26/-24 4,720 3,087 -1,633 -34.6% 2.82 2.68
LeanPool/DomainTheory/Neighborhood/Exercise618.lean +6/-12 12,845 11,360 -1,485 -11.6% 4.82 5.02
LeanPool/DomainTheory/Neighborhood/Product.lean +14/-11 14,559 13,146 -1,413 -9.7% 5.24 4.27
LeanPool/DomainTheory/Neighborhood/Exercise318.lean +18/-15 13,419 12,036 -1,383 -10.3% 5.40 4.72
LeanPool/DomainTheory/Neighborhood/Theorem69.lean +4/-8 6,741 5,384 -1,357 -20.1% 3.12 2.81
LeanPool/DomainTheory/Neighborhood/Exercise515.lean +5/-5 11,198 10,274 -924 -8.3% 5.05 3.92
LeanPool/DomainTheory/Neighborhood/Theorem76.lean +8/-11 6,977 6,134 -843 -12.1% 3.12 2.88
LeanPool/DomainTheory/Neighborhood/Exercise514.lean +0/-2 5,733 4,940 -794 -13.8% 3.04 3.15
LeanPool/DomainTheory/Neighborhood/Exercise421.lean +6/-5 5,011 4,235 -776 -15.5% 3.56 2.85
LeanPool/DomainTheory/Neighborhood/Exercise419.lean +8/-14 15,998 15,252 -746 -4.7% 4.07 3.45
LeanPool/DomainTheory/Neighborhood/Exercise425.lean +7/-10 3,714 2,968 -746 -20.1% 2.55 2.77
LeanPool/DomainTheory/Neighborhood/Theorem56.lean +1/-7 7,455 6,711 -743 -10.0% 3.31 4.05
LeanPool/DomainTheory/Neighborhood/ExampleB.lean +3/-4 2,787 2,152 -636 -22.8% 2.54 2.12
LeanPool/DomainTheory/Neighborhood/Exercise221.lean +8/-8 4,901 4,340 -561 -11.4% 2.74 2.84
LeanPool/DomainTheory/Neighborhood/Example44.lean +5/-9 2,915 2,361 -554 -19.0% 3.15 2.44
LeanPool/DomainTheory/Neighborhood/Example61.lean +32/-21 17,722 17,177 -545 -3.1% 5.55 6.15
LeanPool/DomainTheory/Neighborhood/Exercise415.lean +3/-7 1,513 1,019 -494 -32.7% 2.48 1.97
LeanPool/DomainTheory/Neighborhood/Exercise123.lean +2/-3 5,485 4,999 -485 -8.8% 3.35 3.28
LeanPool/DomainTheory/Neighborhood/Exercise125.lean +1/-1 8,252 7,848 -404 -4.9% 3.74 3.68
LeanPool/DomainTheory/Neighborhood/Example43.lean +6/-10 3,172 2,811 -361 -11.4% 2.52 2.33
LeanPool/DomainTheory/Neighborhood/Lemma615.lean +1/-7 10,810 10,462 -347 -3.2% 2.87 3.24
LeanPool/DomainTheory/Neighborhood/Exercise117.lean +1/-1 2,328 2,002 -326 -14.0% 3.70 3.40
LeanPool/DomainTheory/Neighborhood/Exercise627.lean +0/-7 12,361 12,070 -292 -2.4% 5.41 4.36
LeanPool/DomainTheory/Neighborhood/Exercise408.lean +1/-7 1,915 1,633 -282 -14.8% 2.82 1.91
LeanPool/DomainTheory/Neighborhood/Theorem56Full.lean +8/-11 21,210 20,954 -256 -1.2% 7.42 5.77
LeanPool/DomainTheory/Neighborhood/Exercise513.lean +2/-2 5,335 5,102 -233 -4.4% 3.33 3.17
… +70 more files, each with a smaller move (≤ 233 HB); full table in the run's step summary
Total +1,007/-1,153 1,181,799 938,674 -243,125 -20.6% 499.8 439.9

Per-project compile cost (top 2 of 2 projects by |Δ heartbeats|):

Project Files HB base HB head Δ HB Δ HB %
DomainTheory 119 1,181,799 938,673 -243,125 -20.6%
(root) 1 1 1 -0 -0.5%

New files — absolute profile

Total heartbeats: — maxHeartbeats units across 0 valid files (215 added LOC).

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

Count-heartbeats wall-clock total: 0.00 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/DomainTheory/ContinuousLattice/FunctionSpaceTower.lean 19 — — — — — 82 1
LeanPool/DomainTheory/ContinuousLattice/InverseLimits.lean 9 — — — — — 76 1
LeanPool/DomainTheory/Neighborhood/Exercise617.lean 12 — — — — — 145 1
LeanPool/DomainTheory/Neighborhood/Exercise617Gen.lean 39 — — — — — 636 1
LeanPool/DomainTheory/Neighborhood/Exercise619PartB.lean 23 — — — — — 129 1
LeanPool/DomainTheory/Neighborhood/Exercise621.lean 22 — — — — — 169 1
LeanPool/DomainTheory/Neighborhood/Exercise623.lean 91 — — — — — 165 1
Total 215 — 0.00 — — — 1402 7

Aggregate phase totals

Phase Time
Unavailable —

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

This branch has not been deployed

No deployments
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