Skip to content

Speed up FastDynamo resolvent and cutoff compilation - #1073

Merged
Vilin97 merged 1 commit into
mainfrom
vilin/optimize-fast-dynamo-20261128
Nov 28, 2026
Merged

Vilin97 merged 1 commit into
mainfrom
vilin/optimize-fast-dynamo-20261128

Conversation

@Vilin97

@Vilin97 Vilin97 commented Nov 28, 2026

Copy link
Copy Markdown
Collaborator

Ready for review. The controlled 151-module incremental rebuild is 14.4% faster.

Scope

FastDynamo has 412 modules. The scouting profile showed concentrated costs on the import chain
through the horizontal form operator, its contour resolvent, and the seed perturbation. In the
baseline, HorizontalRieszPerturbation repeatedly compared normed-space instances for the
same graph domains.

  • Keep the associated-form defect and Fourier graphs bundled during elaboration with local
    irreducibility where those bodies are expensive to unfold.
  • Reuse the pencil identity in the two inverse arguments. Apply monotonicity of the square and
    inverse directly in the norm estimates.
  • Use linear-map identities for the zero and additive cases of the Fourier cutoff proof,
    and use the scalar Young inequality and norm bounds directly in the diffusion estimates.

Declaration audit

Lean loaded the full project with private olean data and recorded the exported view separately.
The compressed manifests contain the elaborated expression graphs, universe parameters,
declaration kinds, safety, reducibility, non-theorem values, and constructor and recursor data.
All 14,260 pre-existing declarations matched, including private and generated declarations.
The single added declaration is a private pencil identity used by the optimized proofs.
The comparison permits updated proof terms for existing theorems.

The measured baseline is 432e18b03cfb58eca4e6ee9b3244d6bd6657140e. The PR base is a81b589c8a852c75d03cff1ac873920cb8bc8441. The FastDynamo sources,
build plugin, and dependency pins match at both base commits. The PR head is 69558659b266a4722fc617dad0172622161e25e4.

Measurements

Both clean pairs rebuilt all 412 project modules on the same Azure VM with pinned Lean and
Mathlib v4.36.0 and cached dependencies. The memory sampler recorded the largest per-compiler
RssAnon + VmSwap approximately every 250 ms.

The incremental run retained cached outputs outside the 151-module set of edited modules and their transitive importers. Both revisions rebuilt that same set through the whole-project Imports target.

Metric Base Optimized
Two-thread incremental build wall 301.46 s 258.06 s
Two-thread incremental build CPU 1019.73 s 902.46 s
Four-thread clean build wall 468.22 s 436.95 s
Four-thread clean build CPU 2446.38 s 2255.96 s
Four-thread sampled anonymous peak 399,696 KiB 382,100 KiB
Four-thread maximum RSS, including mapped files 1,801,528 KiB 1,776,408 KiB
Two-thread clean build wall 574.62 s 553.12 s
Two-thread clean build CPU 1999.22 s 1933.19 s
Two-thread sampled anonymous peak 401,660 KiB 392,076 KiB
HorizontalRieszPerturbation, four-thread Lake time 62s 13s
HorizontalRieszPerturbation, cumulative typeclass inference 33.5s 10.2s

Each row reports one paired run on the shared VM. An earlier four-thread scouting baseline
took 447.68 s with partial memory sampling. The cumulative typeclass
measurement uses Lean's --profile with Lake's per-module setup.

Validation

  • LEAN_NUM_THREADS=4 /usr/bin/time -v lake --no-cache --wfail build LeanPool.FastDynamo.Imports
    and the equivalent two-thread command
  • lake env lean --run scripts/ci/lint-project.lean over all 412 modules and
    lake exe lint-style LeanPool.FastDynamo.Imports
  • lake exe mk_all --module --check and uv run --locked python -m lean_pool.quality --repo .. --static-only
    from python/
  • The repository quality checker's project-card, allowed-axiom, environment and compiler-message audits
  • python -m lean_pool.build_time_limits check against the optimized build log for all 22 edited modules
  • lake shake --force --keep-public LeanPool.FastDynamo.Imports for import analysis

@greptile-apps

greptile-apps Bot commented Nov 28, 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 proof-only changes appear safe to merge; no actionable regression was found.RetriggerView in Greptile

[Medium impact] The proof-only changes appear safe to merge; no actionable regression was found.

Summary

This PR speeds up existing FastDynamo proofs without changing their mathematical statements.

  • Horizontal resolvent proofs keep their graph domains bundled during elaboration.
  • Fourier cutoff proofs use direct map and coefficient identities.
  • Diffusion and energy estimates use direct inequality steps.

The supplied paired measurements report faster builds. Those measurements and the declaration audit were not independently rerun. External source and license claims were not reverified; this PR changes neither.

Reviews (1) · Last reviewed commit: "Speed up FastDynamo resolvent and cutoff..." · 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.

Source review passed at 69558659b266a4722fc617dad0172622161e25e4.

  • The resolvent and cutoff changes preserve the existing statements. The pencil identity, linear-map identities, and explicit norm inequalities replace repeated elaboration work. The reducibility attributes are local to the proof modules. There are no import, project-card, or attribution changes.
  • The FastDynamo tree, toolchain, Lake inputs, and build scripts match at the benchmark base and PR base. The reported paired incremental run improves from 301.46 s to 258.06 s, a 14.4% reduction. Both reported clean pairs also improved.
  • The right-inverse proof could reuse the same private pencil identity, and two hf bindings became unused. These are optional cleanups. Resolvent source

Required Lean CI and the advisory Proof Profile are running. Lean Action CI · Proof Profile

@github-actions

Copy link
Copy Markdown
Contributor

Proof profile (new / modified Lean files)

Statement changes

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

Also: 1 declaration 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 (1)
  • FastDynamo.associatedFormProdOperator_pencil_apply — LeanPool/FastDynamo/Local/HorizontalFormResolvent.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: 2,451,050 → 2,130,984 (-320,066, -13.1%). Commands: 365 → 373.

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

Files: 4 compared — 3 cheaper, 0 costlier, 1 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/FastDynamo/Local/HorizontalFormResolvent.lean +20/-16 817,343 612,898 -204,445 -25.0% 83.18 84.85
LeanPool/FastDynamo/Local/HorizontalWeakForm.lean +7/-4 1,178,855 1,104,058 -74,797 -6.3% 86.25 87.12
LeanPool/FastDynamo/Analysis/TransverseWeightedDiffusion.lean +6/-9 341,838 301,014 -40,824 -11.9% 42.82 36.42
LeanPool/FastDynamo/Local/HorizontalSeedWitness.lean +2/-0 113,014 113,015 +0 +0.0% 9.95 13.26
Total +35/-29 2,451,050 2,130,984 -320,066 -13.1% 222.2 221.7

New files — absolute profile

Total heartbeats: 2,446,615 maxHeartbeats units across 6 valid files (93 added LOC).

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

Count-heartbeats wall-clock total: 300.56 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/FastDynamo/Local/HorizontalDeltaResolvent.lean 2 813,806 100.50 — — — 44 0
LeanPool/FastDynamo/Local/HorizontalModeWeakIdentity.lean 2 665,308 69.04 — — — 55 0
LeanPool/FastDynamo/Local/HorizontalModeContour.lean 2 329,560 37.95 — — — 62 0
LeanPool/FastDynamo/Local/HorizontalSpectrumEigenvalue.lean 2 323,276 30.74 — — — 19 0
LeanPool/FastDynamo/Local/HorizontalModeEigenpair.lean 2 175,600 27.74 — — — 33 0
LeanPool/FastDynamo/Local/HorizontalFormDelta.lean 2 139,064 34.59 — — — 36 0
LeanPool/FastDynamo/Analysis/TransverseSmoothBumpH2CutoffConcrete.lean 7 — — — — — 94 1
LeanPool/FastDynamo/Analysis/TransverseSmoothH2CutoffMultiplier.lean 21 — — — — — 108 1
LeanPool/FastDynamo/Dynamics/Assembly/ProductResolvent.lean 3 — — — — — 53 1
LeanPool/FastDynamo/Global/TorusBackgroundWeightedEnergy.lean 15 — — — — — 43 1
LeanPool/FastDynamo/Local/HorizontalFormCompactness.lean 2 — — — — — 44 1
LeanPool/FastDynamo/Local/HorizontalFormOperator.lean 4 — — — — — 37 1
LeanPool/FastDynamo/Local/HorizontalModeIsolation.lean 2 — — — — — 64 1
LeanPool/FastDynamo/Local/HorizontalRieszPerturbation.lean 17 — — — — — 66 1
LeanPool/FastDynamo/Local/HorizontalSeedResolventH2.lean 2 — — — — — 74 1
LeanPool/FastDynamo/Local/HorizontalSeedUniformResolvent.lean 2 — — — — — 69 1
LeanPool/FastDynamo/Local/LocalSeedC2Concrete.lean 2 — — — — — 28 1
LeanPool/FastDynamo/Local/WholePlaneC2.lean 4 — — — — — 57 1
Total 93 2,446,615 300.56 — — — 986 12

Aggregate phase totals

Phase Time
Unavailable —

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

@Vilin97

Vilin97 commented Nov 28, 2026

Copy link
Copy Markdown
Collaborator Author

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

Reviewed head: 69558659b266a4722fc617dad0172622161e25e4

Verdict: ✅ approve

The refactor keeps graph definitions bundled during elaboration and replaces broad tactic calls with explicit map identities, cancellation lemmas, and norm inequalities. The targeted Lake build passed for 17 of the 22 edited files, including every rewritten proof. Against identical imports, HorizontalRieszPerturbation went from 1.39 million to 0.40 million elaboration heartbeats. The 151-module rebuild timing is contributor-reported.

Aspect Value
Scope elaboration performance refactor
Introduces tech debt 🛑 yes
Maintainability ✅ improved
Brittleness ✅ more_robust
Risk ✅ low

The explicit proof steps and lower elaboration cost improve maintainability, with minor cleanup remaining in the transparency overrides and pencil helper reuse.

Findings (3)

  • duplicated-proof — LeanPool/FastDynamo/Local/HorizontalFormResolvent.lean:128
    The right inverse still proves the same pencil formula as associatedFormProdOperator_pencil_apply, leaving two places to update if the pencil representation changes. Use the helper here too and drop the unused with hf bindings in its two existing callers. This cleanup elaborated in a scratch copy.
  • unnecessary-opacity — LeanPool/FastDynamo/Analysis/TransverseSmoothH2CutoffMultiplier.lean:623
    The two local MeasureTheory.Lp overrides affect conversion across the cutoff module. Removing both still elaborated and took about 4,500 fewer heartbeats, with almost all of the difference in the second section. Drop the overrides or scope them to proofs where they show a measured benefit.
  • dead-leftover — LeanPool/FastDynamo/Local/HorizontalFormCompactness.lean:64
    Removing the local associatedFormProdGraphDefect override here and in HorizontalSeedWitness left both files compiling and changed each count by about 11 heartbeats. Drop these two copies so the workaround identifies modules where keeping the defect bundled materially affects elaboration.

Tokens: 5,572,680 in / 23,387 out · Tier: codex-subscription · Effort: xhigh · Billing: Codex subscription quota (no API credits) · Estimated cost: $22.6415 (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 28, 2026
Merged via the queue into main with commit efdd6f8 Nov 28, 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