Skip to content

Speed up closed-immersion vanishing rebuilds - #1208

Open
Vilin97 wants to merge 1 commit into
mainfrom
vilin/grothendieck-closed-immersion-20261206
Open

Vilin97 wants to merge 1 commit into
mainfrom
vilin/grothendieck-closed-immersion-20261206

Conversation

@Vilin97

@Vilin97 Vilin97 commented Dec 6, 2026

Copy link
Copy Markdown
Collaborator

Ready for review. The warm closed-immersion assembly rebuild takes 77.48% less time.

Project and changes

GrothendieckVanishing has 28 modules at base. The November 30 source profile at 646bda5fb5e4463b9b20fe648998f9924d4d769a reported 70.25 seconds for CohomologyCalculus, about 36% of its 194.2 seconds of summed module time. I investigated that concentration first. The declaration audit rejected the attempted calculus splits. The closed-immersion module had a separate opportunity to cache the pushforward isomorphism across assembly edits. Lean Pool source profile

  • Move PushforwardHIso and its supporting instance to ClosedImmersionPushforward.lean. ClosedImmersionCohomology.lean publicly re-exports the new module, so existing import paths still expose these declarations.
  • Share the stalk-vanishing argument for the kernel of restriction to a closed subset between the irreducible and reducible cases. Use direct surjectivity and injectivity to transport subsingleton cohomology in the closed-immersion sequence. Reuse the dimension bound for the chosen irreducible component and use explicit finite-union lemmas in the reducible case.

Declaration audit

Base 6b508831f8e5ea6ded0883ba2b3198560d5b1335 and head 3d18cd54e3ee50cdda883f7333e2c943fbd18499. The compressed snapshots were produced with lake env lean --run and imported the project's modules at Lean's private and exported levels. All 496 existing declarations matched in name, universe parameters, kind, safety, visibility, and elaborated type. All 81 existing definition values matched. The only raw differences for existing declarations were 28 source-module records and nine generated binder hygiene tags in PushforwardHIso and three of its proof auxiliaries. The comparison normalized only those tags. Lean's own Expr.eqv independently confirmed the types and definition values through the original import path. The one new declaration is the shared stalk lemma.

Measurements

Lean v4.36.0 and Mathlib fc4f59e577feb1a4956671bc04ac18aaaf8cd842 on the same Azure VM. Each side used the same CPU affinity, four Lean threads, and prebuilt dependency outputs.

taskset -c 8-11 env LEAN_NUM_THREADS=4 lake --no-cache --no-ansi --wfail build LeanPool.GrothendieckVanishing.Imports

Clean trials removed all of this project's Lake outputs. Warm trials removed only ClosedImmersionCohomology.* from the project's Lake library and IR output directories before rebuilding the same target. The sampler read RssAnon + VmSwap about every 100 ms. Combined memory sums the project compiler processes active at each sample.

Measure Base median Head median Change
Warm rebuild wall time (s) 19.476 4.386 77.48% lower
Warm rebuild peak compiler memory (KiB) 895,056 337,008 62.35% lower
Clean project wall time (s) 146.6415 151.101 3.04% higher
Clean peak individual compiler memory (KiB) 1,227,390 1,226,186 0.10% lower
Clean peak combined compiler memory (KiB) 1,404,712 1,534,958 9.27% higher
  • Warm rebuild wall time (s). Base 19.485, 19.476, 19.144. Head 5.896, 4.278, 4.386.
  • Warm rebuild peak compiler memory (KiB). Base 895,676, 889,032, 895,056. Head 339,092, 335,272, 337,008.
  • Clean project wall time (s). Base 147.73, 145.553. Head 152.935, 149.267.
  • Clean peak individual compiler memory (KiB). Base 1,217,952, 1,236,828. Head 1,218,668, 1,233,704.
  • Clean peak combined compiler memory (KiB). Base 1,348,720, 1,460,704. Head 1,513,236, 1,556,680.

The 10% target is met for the warm assembly workload. A clean build still compiles the pushforward isomorphism. Combined memory depends on which Lean processes overlap on this VM.

Validation

  • Warning-free project build and repository timing check for changed Lean files.
  • Mathlib declaration linters over 29 modules and 497 declarations, plus declaration, trusted-axiom, environment-backdoor, and build-message audits through python -m lean_pool.shard_validation --repo .. --units GrothendieckVanishing.
  • lake exe lint-style LeanPool.GrothendieckVanishing.Imports, python -m lean_pool.quality --repo .. --static-only from python/, and git diff --check.
  • lake exe mk_all --module --check and lake exe mk_all --check. Used lake shake --force --keep-public LeanPool.GrothendieckVanishing.Imports for import analysis.

@greptile-apps

greptile-apps Bot commented Dec 6, 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.

[Low impact] The refactor appears mergeable; no actionable regression was found.

RetriggerView in Greptile

Summary

Moves PushforwardHIso into a separate module so edits to the closed-immersion assembly can reuse its compiled output.

  • Closed-inclusion cohomology comparisons compile separately from the assembly proof.
  • Both vanishing proofs use one rule for closed-immersion kernel stalks.

Vilin97 explicitly disclosed the higher clean-build time and combined memory use. These are acknowledged tradeoffs: clean builds still compile the moved proof, and overlapping compiler processes affect combined memory.

Reviewed the project card, headline type, imports, consumers, and preserved attribution. External source history and license provenance were not independently verified. Performance measurements and validation results are author-supplied; they were not rerun.

Reviews (1) · Last reviewed commit: "Speed up closed-immersion vanishing rebu..." · Reviewed by Greptile

@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 on source review of 3d18cd54e3ee50cdda883f7333e2c943fbd18499. Required CI and the configured review are pending.

PushforwardHIso and its supporting instance move unchanged. ClosedImmersionCohomology still publicly imports them, so existing imports continue to expose the declarations. The shared kernel-stalk lemma uses the unit's stalk isomorphism on the closed subset and ambient stalk vanishing off it. Both callers retain the same hypotheses, and the middle-cohomology argument transports subsingleton structure along the corresponding surjection and injection. The three modified theorem headers match the base.

The reported median warm assembly rebuild fell from 19.48 s to 4.39 s. Clean project time rose from 146.64 s to 151.10 s, and combined peak compiler memory rose by 9.27% while individual peak memory was essentially flat. The split pays off when the assembly changes and the compiled pushforward proof can be reused. I checked the source delta and the declaration audit reported in the PR. The performance figures are the author's measurements.

@github-actions

github-actions Bot commented Dec 6, 2026

Copy link
Copy Markdown
Contributor

Proof profile (new / modified Lean files)

lake build wall time (changed modules): 36.37 s (= 0.61 min) — user 25.67 s, sys 3.22 s.

This build covers the changed modules and their dependency cones on top of the restored cache. The serial per-file sums below are useful for ranking slow files, not as a build budget.

A base→head comparison was attempted but its measurements are unavailable (see the run log); modified files are omitted from the tables below.

Statement changes

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

Also: 1 declaration added, 2 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)
  • closedImmersionSES_stalk_kernel_eq_zero — LeanPool/GrothendieckVanishing/ClosedImmersionCohomology.lean
➖ Declarations removed (2)
  • PushforwardHIso — LeanPool/GrothendieckVanishing/ClosedImmersionCohomology.lean
  • subtypeSheafHAddCommGroup — LeanPool/GrothendieckVanishing/ClosedImmersionCohomology.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.

Total heartbeats: 263,052 maxHeartbeats units across 1 valid file (119 added LOC).

Sum of lean --profile: 21138.7 ms (= 21.14 s) across 1 valid file. Import-excluded time: 20230.7 ms (= 20.23 s).

Count-heartbeats wall-clock total: 27.01 s. Repeated import cost inside lean --profile: 908.0 ms (= 0.91 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/GrothendieckVanishing/ClosedImmersionPushforward.lean 84 263,052 27.01 21.14 20.23 0.91 7 0
LeanPool/GrothendieckVanishing/ClosedImmersionCohomology.lean 22 — — — — — 0 1
LeanPool/GrothendieckVanishing/Imports.lean 1 — — — — — 0 1
LeanPool/GrothendieckVanishing/IrreducibleStep.lean 3 — — — — — 19 1
LeanPool/GrothendieckVanishing/ReducibleVanishing.lean 9 — — — — — 7 1
Total 119 263,052 27.01 21.14 20.23 0.91 33 4

Aggregate phase totals

Phase Time
type checking 17700.0 ms (= 17.70 s)
typeclass inference 1650.0 ms (= 1.65 s)
import 908.0 ms (= 0.91 s)
let-to-have transformation 460.0 ms (= 0.46 s)
tactic execution 182.0 ms (= 0.18 s)
interpretation 116.0 ms (= 0.12 s)
elaboration 36.6 ms (= 0.04 s)
initialization 30.1 ms (= 0.03 s)
process pre-definitions 27.2 ms (= 0.03 s)
simp 9.7 ms (= 0.01 s)
linting 4.6 ms (= 0.00 s)
share common exprs 3.6 ms (= 0.00 s)

Slowest changed modules (from lake build)

Changed module Lake time
LeanPool.GrothendieckVanishing.ClosedImmersionPushforward 21.00 s
Per-file `lean --profile` output

LeanPool/GrothendieckVanishing/ClosedImmersionPushforward.lean

import took 908ms
type checking took 640ms
let-to-have transformation took 460ms
type checking took 672ms
type checking took 305ms
type checking took 293ms
type checking took 642ms
type checking took 1.41s
type checking took 986ms
type checking took 1.34s
type checking took 1.37s
type checking took 1.43s
type checking took 1.39s
type checking took 7.24s
cumulative profiling times:
	attribute application 1.46ms
	congr simp thm 0.383ms
	declTypeLinter 2ms
	elaboration 36.6ms
	fix level params 1.16ms
	import 908ms
	initialization 30.1ms
	instantiate metavars 1.94ms
	interpretation 116ms
	let-to-have transformation 460ms
	linting 4.62ms
	module linting 0.025ms
	parsing 2.68ms
	process pre-definitions 27.2ms
	share common exprs 3.59ms
	simp 9.74ms
	tactic execution 182ms
	tacticAnalysis 1.19ms
	type checking 17.7s
	typeclass inference 1.65s
real 20.54
user 20.43
sys 0.94

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