Skip to content

Speed up ExtriangulatedRealization builds - #1054

Merged
Vilin97 merged 1 commit into
mainfrom
vilin/optimize-extriangulated-realization-20261127
Nov 27, 2026
Merged

Vilin97 merged 1 commit into
mainfrom
vilin/optimize-extriangulated-realization-20261127

Conversation

@Vilin97

@Vilin97 Vilin97 commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator

Ready for review. The ExtriangulatedRealization clean build took 25.9% less wall time in the matched Azure VM run.

Changes

The source profile put about 41% of the project's source-attributed time in Shadow and Extensions. The project had 61 modules, and the expensive realization steps were on the same build path. Lean Pool source profile

  • Check the matrix-lift composition equality over abstract categories and functors before specializing it to the derived category.
  • Put the connecting maps in ExtensionMaps, so their naturality and bijectivity proofs in Extensions can compile alongside TriangleProofs. The original Extensions and Triangles imports still expose their original declarations.
  • Cancel the mapped comparison isomorphisms in a private categorical lemma. Keep kInj and realTriangle together so Lean reuses the original generated cancellation proof. Regenerate the project's public import index.

Declaration audit

Read the exported, server, and private .olean constant tables with Lean before and after the changes. Compared SHA-256 digests of the full expression DAGs, including binder annotations, universe parameters, declaration kind, safety, and non-proof values. The only normalization was the source-module component of generated inst binder scope names in the two moved modules.

All 1,606 existing names matched, including private and generated declarations. There were 28 module moves, 9 proof-term differences, and 2 new private lemmas. Direct imports of the original entry paths were checked by Lean.

Measurements

PR base ec62f980b01d724d60cb0577e6ab9f9643fdbfb3. The matched pair used base ec62f980b01d724d60cb0577e6ab9f9643fdbfb3, Lean v4.36.0, and Mathlib fc4f59e577feb1a4956671bc04ac18aaaf8cd842. Each run removed the selected project's .lake/build/lib/lean and .lake/build/ir outputs and reused the pinned dependency artifacts. The target built 61 modules at base and 63 at head.

Metric Base Head
Wall time 209.40 s 155.21 s
User CPU time 306.97 s 251.23 s
System CPU time 21.47 s 20.28 s
Peak RSS, GNU time 2,508,664 KiB 2,411,524 KiB

Lake measured Shadow at 44s → 34s. Base Extensions and Triangles took 48s and 22s in sequence. At head, ExtensionMaps took 21s, then Extensions and TriangleProofs took 16s and 16s in parallel. The Triangles wrapper took 794ms.

Two earlier clean pairs at a157db851b8d55765ffd95db8876c7ef6e73c9de, before spelling-only changes to the new private binders, measured 172.85 → 141.64 s and 178.08 → 158.83 s. Additional head rebuilds during higher load measured 179.11 s and 171.13 s. Wall time on the shared VM varies with other workloads.

Validation

/usr/bin/time -f 'wall_s=%e user_s=%U sys_s=%S max_rss_kib=%M' \
  env LEAN_NUM_THREADS=4 lake --no-ansi --wfail build LeanPool.ExtriangulatedRealization.Imports
lake shake --force --keep-public LeanPool.ExtriangulatedRealization.Imports
lake env lean --run scripts/ci/lint-project.lean "${modules[@]}"
lake exe lint-style LeanPool.ExtriangulatedRealization.Imports
PYTHONPATH=python uv run --project python --locked python -m lean_pool.quality --repo . --static-only
lake exe mk_all --module --check

lake shake reported advisory import suggestions. The new branch dependencies use ExtensionMaps directly, and the old public imports retain their exports.

The project also passed the repository's axiom, option-backdoor, compiler-message, and project-card declaration checks for every selected module, plus the root and documentation toolchain and Mathlib pin checks. Local compiled validation covered the selected project. The whole-pool build runs in GitHub CI.

@greptile-apps

greptile-apps Bot commented Nov 27, 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.

The refactor appears safe to merge, with existing declarations and import paths preserved.RetriggerView in Greptile

[Low impact] The refactor appears safe to merge, with existing declarations and import paths preserved.

Summary

Splits the connecting-map definitions and triangle proofs so they can build on separate paths. Two private helpers check expensive proof steps over abstract categories.

  • Extension-map proofs compile in separate modules.
  • Realization-triangle proofs compile in their own module.
  • The shadow comparison reuses an abstract matrix-lift equality.

Reviews (1) · Last reviewed commit: "Speed up ExtriangulatedRealization build..." · Reviewed by Greptile

@github-actions

Copy link
Copy Markdown
Contributor

Proof profile (new / modified Lean files)

lake build wall time (changed modules): 98.33 s (= 1.64 min) — user 80.16 s, sys 6.22 s.

This build covers the added modules and their dependency cones on top of the measurement environment; modified files are measured without rebuilding the pool.

Statement changes

✅ No statements changed — all 21 tracked declarations across 4 modified files kept their type; only proofs / definition bodies changed.

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

➕ Declarations added (1)
  • ExtriangulatedRealization.RealizationData.matLift_comp_mapMat_lift — LeanPool/ExtriangulatedRealization/Realization/Shadow.lean
➖ Declarations removed (21)
  • ExtriangulatedRealization.RealizationData.dataJ — LeanPool/ExtriangulatedRealization/Realization/Extensions.lean
  • ExtriangulatedRealization.RealizationData.eta — LeanPool/ExtriangulatedRealization/Realization/Extensions.lean
  • ExtriangulatedRealization.RealizationData.etaTarget — LeanPool/ExtriangulatedRealization/Realization/Extensions.lean
  • ExtriangulatedRealization.RealizationData.etaTarget_apply — LeanPool/ExtriangulatedRealization/Realization/Extensions.lean
  • ExtriangulatedRealization.RealizationData.realP — LeanPool/ExtriangulatedRealization/Realization/Extensions.lean
  • ExtriangulatedRealization.RealizationData.shadowRealPIso — LeanPool/ExtriangulatedRealization/Realization/Extensions.lean
  • ExtriangulatedRealization.RealizationData.shadow_bijective_realP — LeanPool/ExtriangulatedRealization/Realization/Extensions.lean
  • ExtriangulatedRealization.RealizationData.shadow_map_eta — LeanPool/ExtriangulatedRealization/Realization/Extensions.lean
  • ExtriangulatedRealization.RealizationData.XFree.of_iso — LeanPool/ExtriangulatedRealization/Realization/Triangles.lean
  • ExtriangulatedRealization.RealizationData.goodObj — LeanPool/ExtriangulatedRealization/Realization/Triangles.lean
  • ExtriangulatedRealization.RealizationData.goodObj_cone — LeanPool/ExtriangulatedRealization/Realization/Triangles.lean
  • ExtriangulatedRealization.RealizationData.goodObj_realF — LeanPool/ExtriangulatedRealization/Realization/Triangles.lean
  • ExtriangulatedRealization.RealizationData.goodObj_realP — LeanPool/ExtriangulatedRealization/Realization/Triangles.lean
  • ExtriangulatedRealization.RealizationData.goodObj_shift — LeanPool/ExtriangulatedRealization/Realization/Triangles.lean
  • ExtriangulatedRealization.RealizationData.hom_to_X_eq_zero — LeanPool/ExtriangulatedRealization/Realization/Triangles.lean
  • ExtriangulatedRealization.RealizationData.realTriangle — LeanPool/ExtriangulatedRealization/Realization/Triangles.lean
  • ExtriangulatedRealization.RealizationData.realTriangle_distinguished_of_xFree — LeanPool/ExtriangulatedRealization/Realization/Triangles.lean
  • ExtriangulatedRealization.RealizationData.shadow_map_bijective_of_goodObj — LeanPool/ExtriangulatedRealization/Realization/Triangles.lean
  • ExtriangulatedRealization.RealizationData.shadow_realTriangle_distinguished — LeanPool/ExtriangulatedRealization/Realization/Triangles.lean
  • ExtriangulatedRealization.kInj — LeanPool/ExtriangulatedRealization/Realization/Triangles.lean
  • ExtriangulatedRealization.kInj_resK — LeanPool/ExtriangulatedRealization/Realization/Triangles.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: 654,596 → 481,988 (-172,608, -26.4%). Commands: 37 → 39.

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

Files: 1 compared — 1 cheaper, 0 costlier, 0 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/ExtriangulatedRealization/Realization/Shadow.lean +8/-1 654,596 481,988 -172,608 -26.4% 82.73 49.98
Total +8/-1 654,596 481,988 -172,608 -26.4% 82.7 50.0

New files — absolute profile

Total heartbeats: 712,005 maxHeartbeats units across 2 valid files (317 added LOC).

Sum of lean --profile: 42313.1 ms (= 42.31 s) across 2 valid files. Import-excluded time: 39960.1 ms (= 39.96 s).

Count-heartbeats wall-clock total: 49.59 s. Repeated import cost inside lean --profile: 2353.0 ms (= 2.35 s).

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/ExtriangulatedRealization/Realization/TriangleProofs.lean 214 461,592 25.19 20.58 19.91 0.67 55 0
LeanPool/ExtriangulatedRealization/Realization/ExtensionMaps.lean 93 250,413 24.40 21.73 20.05 1.68 25 0
LeanPool/ExtriangulatedRealization/Imports.lean 2 — — — — — 0 1
LeanPool/ExtriangulatedRealization/Realization/Extensions.lean 5 — — — — — 0 1
LeanPool/ExtriangulatedRealization/Realization/Triangles.lean 3 — — — — — 0 1
Total 317 712,005 49.59 42.31 39.96 2.35 80 3

Aggregate phase totals

Phase Time
type checking 35900.0 ms (= 35.90 s)
import 2353.0 ms (= 2.35 s)
tactic execution 1810.0 ms (= 1.81 s)
typeclass inference 880.0 ms (= 0.88 s)
elaboration 722.0 ms (= 0.72 s)
interpretation 310.0 ms (= 0.31 s)
linting 63.4 ms (= 0.06 s)
initialization 56.2 ms (= 0.06 s)
process pre-definitions 53.6 ms (= 0.05 s)
attribute application 52.7 ms (= 0.05 s)
simp 29.0 ms (= 0.03 s)
share common exprs 25.2 ms (= 0.03 s)

Slowest changed modules (from lake build)

Changed module Lake time
LeanPool.ExtriangulatedRealization.Realization.Shadow 33.00 s
LeanPool.ExtriangulatedRealization.Realization.ExtensionMaps 19.00 s
LeanPool.ExtriangulatedRealization.Realization.TriangleProofs 16.00 s
Per-file `lean --profile` output

LeanPool/ExtriangulatedRealization/Realization/ExtensionMaps.lean

import took 1.68s
type checking took 9.41s
type checking took 542ms
elaboration took 117ms
type checking took 3.04s
elaboration took 139ms
type checking took 3.75s
type checking took 566ms
type checking took 529ms
type checking took 1.25s
cumulative profiling times:
	attribute application 51ms
	declTypeLinter 7.35ms
	elaboration 492ms
	fix level params 1.13ms
	import 1.68s
	initialization 25.9ms
	instantiate metavars 0.21ms
	interpretation 135ms
	let-to-have transformation 0.469ms
	linting 13.9ms
	module linting 0.0184ms
	parsing 4.37ms
	process pre-definitions 17.8ms
	share common exprs 4.86ms
	tacticAnalysis 2.73ms
	type checking 19.1s
	typeclass inference 197ms
real 21.67
user 20.56
sys 0.97

LeanPool/ExtriangulatedRealization/Realization/TriangleProofs.lean

import took 673ms
type checking took 738ms
tactic execution of Lean.Parser.Tactic.refine took 468ms
tactic execution of Lean.Parser.Tactic.exact took 204ms
type checking took 5.21s
type checking took 1.71s
type checking took 531ms
tactic execution of Lean.Parser.Tactic.refine took 242ms
tactic execution of Lean.Parser.Tactic.change took 127ms
tactic execution of Lean.Parser.Tactic.rewriteSeq took 152ms
type checking took 8.58s
cumulative profiling times:
	attribute application 1.67ms
	congr simp thm 1.29ms
	declTypeLinter 11ms
	elaboration 230ms
	fix level params 5.88ms
	import 673ms
	initialization 30.3ms
	instantiate metavars 6.32ms
	interpretation 175ms
	let-to-have transformation 1ms
	linting 49.5ms
	module linting 0.0343ms
	parsing 12.2ms
	process pre-definitions 35.8ms
	share common exprs 20.3ms
	simp 29ms
	tactic execution 1.81s
	tacticAnalysis 4.06ms
	type checking 16.8s
	typeclass inference 683ms
real 18.69
user 20.34
sys 1.11

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 at cebf74cdfb2e85373d827d3d4d070e0fe48095fc.

  • The connecting-map definitions and naturality proofs moved without changing their statements. The old Extensions and Triangles imports still expose the moved declarations. The matrix-lift equality and the isomorphism cancellation are the same steps factored into private categorical lemmas.
  • The compiled audit accounts for all 1,606 existing names, and the copyright headers are retained. The matched clean build went from 209.40 s to 155.21 s, with user CPU time dropping from 306.97 s to 251.23 s. Hosted profiling also measured 26.4% fewer heartbeats in Shadow.lean. The profile's per-file removals correspond to the declarations moved into the new modules. Proof Profile
  • All applicable required checks passed. Lean Action CI

@Vilin97
Vilin97 added this pull request to the merge queue Nov 27, 2026
@Vilin97

Vilin97 commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator Author

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

Reviewed head: cebf74cdfb2e85373d827d3d4d070e0fe48095fc

Verdict: ✅ approve

The refactor lets the extension-map properties and triangle proofs compile in parallel from a shared module. It checks the matrix-lift equality over abstract functors and isolates isomorphism cancellation in a private lemma with explicit rewrites. The 63-module project build and direct checks of the original Extensions and Triangles imports passed locally. The PR’s /profile comparison reports 26.4% fewer heartbeats for Shadow.

Aspect Value
Scope Module split and proof extraction
Introduces tech debt ✅ no
Maintainability ✅ improved
Brittleness ✅ more_robust
Risk ✅ low

The split shortens the build’s critical path, and the extracted lemmas make failures easier to localize while preserving the import paths callers use.


Tokens: 2,443,516 in / 12,170 out · Tier: codex-subscription · Effort: xhigh · Billing: Codex subscription quota (no API credits) · Estimated cost: $9.9566 (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.

Merged via the queue into main with commit bb99e52 Nov 27, 2026
27 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