Skip to content

Speed up CarlesonLT proof compilation - #1071

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

Vilin97 merged 1 commit into
mainfrom
vilin/optimize-carleson-proofs-20261128

Conversation

@Vilin97

@Vilin97 Vilin97 commented Nov 28, 2026

Copy link
Copy Markdown
Collaborator

Ready for review. The median clean single-core build for CarlesonLT fell by 10.73%.

Project and changes

CarlesonLT has roughly 15,000 lines of Lean. The weekly source profile put ModelOperator.lean at 19.83 s of the project's 39.83 s, with AnisotropicCarleson.lean next on the build path. Profiling identified the joint-continuity proof and frequency-cutoff estimates as candidates for more direct arguments.

  • Compose continuity proofs from the map and phase lemmas, and share Fourier inversion rescaling in the forward and reverse arguments.
  • Reuse scaled integer interval bounds and coordinate estimates. Supply the needed product inequalities directly before linear arithmetic in the cutoff, cube, and tree estimates.
  • Use the geometric limit of the residual tile sum in the key estimate.
  • Build the real and periodic kernel lemmas as an independent module. The classical module publicly imports it, and the generated project index includes it. The changes also remove redundant import edges.

Declaration audit

Base commit 2ba0fbcf895956d8bc5834ee7c423af1872f106a. A Lean environment manifest recorded all 1,473 existing declarations, including private and generated declarations, before editing. The comparison checked names, elaborated types, universe parameters, declaration kind, safety, exposure, reducibility, and non-proof values and recursor rules. All existing declarations matched. The raw differences were the module of origin for 28 relocated declarations and numeric macro-hygiene labels on bound variables in six generated private proofs. The comparison erased macro scopes only from private theorem binder names. Twelve supporting and compiler-generated declarations were added. Separate exported-environment checks matched the external declaration sets for the project index and the classical, model, and anisotropic entry points.

Clean build measurements

Both worktrees used the pinned Lean and Mathlib versions and shared the same dependency cache. I cleared the selected project's build artifacts before each run and ran lake --wfail --no-ansi build LeanPool.CarlesonLT.Imports under /usr/bin/time -v. Each configuration used four concurrent base/head pairs, with disjoint CPU masks swapped between pairs and one or four Lean threads per build. Peak anonymous memory is the sum of project Lean processes' RssAnon + VmSwap, sampled every 100 ms.

Median measurement Base Patch Reduction
Single-core wall time 140.515 s 125.440 s 10.73%
Single-core user CPU time 134.545 s 119.330 s 11.31%
Single-core peak anonymous memory 1,334,282 KiB 1,280,094 KiB 4.06%
Four-core wall time 67.640 s 62.860 s 7.07%
Four-core user CPU time 164.755 s 146.655 s 10.99%
Four-core peak anonymous memory 1,299,652 KiB 1,263,350 KiB 2.79%

Single-core wall times by pair were 144.85, 116.46, 136.93, and 144.10 s on the base and 132.23, 105.32, 118.65, and 135.62 s on the patch. The median displayed compile time for ModelOperator.lean in that configuration fell from 81 to 65 s. These are targeted builds on one shared Azure VM with cached dependencies. The wall-time gain varies with the worker count and VM load.

Validation

  • Warning-as-error project build and lake shake --force --keep-public --add-public LeanPool.CarlesonLT.Imports.
  • lake env lean --run scripts/ci/lint-project.lean and lake --no-build exe lint-style for all ten project modules.
  • uv run --locked python -m lean_pool.quality --repo .. --static-only from python/ and the repository's project-scoped axiom, option, compiler-message, and headline-declaration audits.
  • lake exe mk_all --module --check, documentation toolchain and Mathlib pin checks, git diff --check, and the ten relevant CI tooling tests for Lake and the compiled axiom audit.

@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 afebc538cb866038e233c0ced929681c8701e622.

  • The revised proofs use explicit continuity, scaling, and interval bounds. The Fourier inversion keeps the same phase and normalization, and the geometric-limit step removes only the residual term. Existing declaration signatures match the base in the two edited proof modules.
  • The extracted kernel declarations retain their names and signatures. ClassicalCarleson publicly imports FourierKernels, and the existing public Mathlib dependencies remain reachable at the pinned revision. The split retains the author, license, and adaptation notices.
  • All four reported single-core clean build pairs improved. The median recalculates to 140.515 s versus 125.440 s, a 10.73% reduction on the reported VM. Hosted validation is still running. Lean Action CI · Proof Profile

@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.

No actionable regression was found in the proof refactor or module extraction.RetriggerView in Greptile

[Medium impact] No actionable regression was found in the proof refactor or module extraction.

Summary

Refactors CarlesonLT proofs to reduce repeated work without changing the existing theorem statements.

  • CarlesonLT proofs compile faster with shared direct estimates.
  • Fourier-kernel lemmas now live in a shared module.

Checked the supplied changes, related callers, public definitions, theorem statements, project card, and repository guidance. The reported build savings were not independently measured. The pinned upstream source and its license were not independently checked; local attribution and metadata remain consistent.

Reviews (1) · Last reviewed commit: "Optimize the CarlesonLT compilation path" · Reviewed by Greptile

@github-actions

Copy link
Copy Markdown
Contributor

Proof profile (new / modified Lean files)

lake build wall time (changed modules): 30.43 s (= 0.51 min) — user 7.67 s, sys 4.09 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 780 tracked declarations across 4 modified files kept their type; only proofs / definition bodies changed.

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

➕ Declarations added (10)
  • CarlesonLT.Auto.continuous_phiHat_rescaled — LeanPool/CarlesonLT/Auto/AnisotropicCarleson.lean
  • CarlesonLT.Auto.continuous_two_pi_toLp — LeanPool/CarlesonLT/Auto/AnisotropicCarleson.lean
  • CarlesonLT.Auto.abs_sub_le_of_mem_halfOpen — LeanPool/CarlesonLT/Auto/ModelOperator.lean
  • CarlesonLT.Auto.conj_div_norm_mul — LeanPool/CarlesonLT/Auto/ModelOperator.lean
  • CarlesonLT.Auto.continuous_cexp_inner — LeanPool/CarlesonLT/Auto/ModelOperator.lean
  • CarlesonLT.Auto.continuous_cexp_neg_inner — LeanPool/CarlesonLT/Auto/ModelOperator.lean
  • CarlesonLT.Auto.fourierInv_rescale — LeanPool/CarlesonLT/Auto/ModelOperator.lean
  • CarlesonLT.Auto.rho_le_of_coordinate_bounds — LeanPool/CarlesonLT/Auto/ModelOperator.lean
  • CarlesonLT.Auto.rho_le_zpow_of_coordinate_bounds — LeanPool/CarlesonLT/Auto/ModelOperator.lean
  • CarlesonLT.Auto.scaled_integer_bounds — LeanPool/CarlesonLT/Auto/ModelOperator.lean
➖ Declarations removed (27)
  • CarlesonLT.Auto.abs_corrPhi_le — LeanPool/CarlesonLT/Auto/ClassicalCarleson.lean
  • CarlesonLT.Auto.corrPhi — LeanPool/CarlesonLT/Auto/ClassicalCarleson.lean
  • CarlesonLT.Auto.corrPsi — LeanPool/CarlesonLT/Auto/ClassicalCarleson.lean
  • CarlesonLT.Auto.corr_bound_pos — LeanPool/CarlesonLT/Auto/ClassicalCarleson.lean
  • CarlesonLT.Auto.cutoffIntegral — LeanPool/CarlesonLT/Auto/ClassicalCarleson.lean
  • CarlesonLT.Auto.dirichletKernel — LeanPool/CarlesonLT/Auto/ClassicalCarleson.lean
  • CarlesonLT.Auto.dirichletPer — LeanPool/CarlesonLT/Auto/ClassicalCarleson.lean
  • CarlesonLT.Auto.dirichletPer_sub_one — LeanPool/CarlesonLT/Auto/ClassicalCarleson.lean
  • CarlesonLT.Auto.dirichletPer_zero — LeanPool/CarlesonLT/Auto/ClassicalCarleson.lean
  • CarlesonLT.Auto.enorm_integral_mul_le — LeanPool/CarlesonLT/Auto/ClassicalCarleson.lean
  • CarlesonLT.Auto.enorm_partialFourierIntegral_sub_le — LeanPool/CarlesonLT/Auto/ClassicalCarleson.lean
  • CarlesonLT.Auto.exists_schwartz_eLpNorm_sub_le — LeanPool/CarlesonLT/Auto/ClassicalCarleson.lean
  • CarlesonLT.Auto.fourierCoeff1 — LeanPool/CarlesonLT/Auto/ClassicalCarleson.lean
  • CarlesonLT.Auto.fourierPartialSum1 — LeanPool/CarlesonLT/Auto/ClassicalCarleson.lean
  • CarlesonLT.Auto.fourierPartialSum1_eq — LeanPool/CarlesonLT/Auto/ClassicalCarleson.lean
  • CarlesonLT.Auto.integrable_char_fourier — LeanPool/CarlesonLT/Auto/ClassicalCarleson.lean
  • CarlesonLT.Auto.integrable_fourier_schwartz — LeanPool/CarlesonLT/Auto/ClassicalCarleson.lean
  • CarlesonLT.Auto.integrable_mul_dirichletKernel — LeanPool/CarlesonLT/Auto/ClassicalCarleson.lean
  • CarlesonLT.Auto.intervalIntegrable_mul_dirichletPer — LeanPool/CarlesonLT/Auto/ClassicalCarleson.lean
  • CarlesonLT.Auto.measurable_corrPsi — LeanPool/CarlesonLT/Auto/ClassicalCarleson.lean
  • CarlesonLT.Auto.measurable_dirichletKernel — LeanPool/CarlesonLT/Auto/ClassicalCarleson.lean
  • CarlesonLT.Auto.memLp_dirichletKernel — LeanPool/CarlesonLT/Auto/ClassicalCarleson.lean
  • CarlesonLT.Auto.norm_dirichletKernel_le — LeanPool/CarlesonLT/Auto/ClassicalCarleson.lean
  • CarlesonLT.Auto.partialFourierIntegral — LeanPool/CarlesonLT/Auto/ClassicalCarleson.lean
  • CarlesonLT.Auto.partialFourierIntegral_sub — LeanPool/CarlesonLT/Auto/ClassicalCarleson.lean
  • CarlesonLT.Auto.tendsto_integral_mul_sin — LeanPool/CarlesonLT/Auto/ClassicalCarleson.lean
  • CarlesonLT.Auto.window — LeanPool/CarlesonLT/Auto/ClassicalCarleson.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,438,882 → 1,833,398 (-605,485, -24.8%). Commands: 809 → 817.

Per-file wall sum: 300.6 s → 223.7 s (-25.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/CarlesonLT/Auto/ModelOperator.lean +333/-367 2,438,882 1,833,398 -605,485 -24.8% 300.57 223.69
Total +333/-367 2,438,882 1,833,398 -605,485 -24.8% 300.6 223.7

New files — absolute profile

Total heartbeats: 64,826 maxHeartbeats units across 1 valid file (403 added LOC).

Sum of lean --profile: 5070.8 ms (= 5.07 s) across 1 valid file. Import-excluded time: 2590.8 ms (= 2.59 s).

Count-heartbeats wall-clock total: 5.76 s. Repeated import cost inside lean --profile: 2480.0 ms (= 2.48 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/CarlesonLT/Auto/FourierKernels.lean 310 64,826 5.76 5.07 2.59 2.48 40 0
LeanPool/CarlesonLT/Auto/AnisotropicCarleson.lean 85 — — — — — 325 1
LeanPool/CarlesonLT/Auto/ClassicalCarleson.lean 7 — — — — — 0 1
LeanPool/CarlesonLT/Imports.lean 1 — — — — — 0 1
Total 403 64,826 5.76 5.07 2.59 2.48 365 3

Aggregate phase totals

Phase Time
import 2480.0 ms (= 2.48 s)
typeclass inference 749.0 ms (= 0.75 s)
interpretation 719.0 ms (= 0.72 s)
tactic execution 467.0 ms (= 0.47 s)
type checking 150.0 ms (= 0.15 s)
simp 101.0 ms (= 0.10 s)
norm_num 80.6 ms (= 0.08 s)
elaboration 71.7 ms (= 0.07 s)
ring 68.7 ms (= 0.07 s)
linting 40.7 ms (= 0.04 s)
process pre-definitions 27.3 ms (= 0.03 s)
blocked (unaccounted) 27.2 ms (= 0.03 s)

Slowest changed modules (from lake build)

Changed module Lake time
LeanPool.CarlesonLT.Auto.FourierKernels 6.20 s
Per-file `lean --profile` output

LeanPool/CarlesonLT/Auto/FourierKernels.lean

import took 2.48s
cumulative profiling times:
	attribute application 0.212ms
	blocked (unaccounted) 27.2ms
	congr simp thm 4.18ms
	declTypeLinter 7.7ms
	elaboration 71.7ms
	fix level params 1.74ms
	import 2.48s
	initialization 25.8ms
	instantiate metavars 4.21ms
	interpretation 719ms
	let-to-have transformation 0.313ms
	linting 40.7ms
	module linting 0.0286ms
	norm_num 80.6ms
	parsing 15ms
	process pre-definitions 27.3ms
	ring 68.7ms
	share common exprs 23.8ms
	simp 101ms
	tactic execution 467ms
	tacticAnalysis 5.57ms
	type checking 150ms
	typeclass inference 749ms
real 4.09
user 3.14
sys 0.90

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: afebc538cb866038e233c0ced929681c8701e622

Verdict: ✅ approve

The refactor replaces broad tactic searches with explicit continuity and inequality lemmas, shares Fourier inversion rescaling, and extracts Fourier kernel definitions and supporting proofs into a standalone module. The warning-as-error build of LeanPool.CarlesonLT.Imports passed with the pinned dependencies. The PR’s /profile comparison reports 24.8% fewer heartbeats for ModelOperator.lean, the only file with a direct comparison.

Aspect Value
Scope Proof optimization and module split
Introduces tech debt 🛑 yes
Maintainability ✅ improved
Brittleness ✅ more_robust
Risk ✅ low

The proof changes make dependencies clearer and reduce tactic search, with minor debt from splitting kernel identities across modules and leaving duplicated algebra.

Findings (3)

  • module-boundary — LeanPool/CarlesonLT/Auto/ClassicalCarleson.lean:120
    The split moves the Dirichlet kernel definitions into FourierKernels while leaving dirichletKernel_eq_integral and dirichletPer_mul_sin behind the anisotropic Carleson import. Move these identities and their supporting lemmas alongside the definitions. Both proofs elaborate in isolation with FourierKernels and Mathlib imports.
  • missed-reuse — LeanPool/CarlesonLT/Auto/ModelOperator.lean:8045
    The nonzero branch of tree_estimate rederives the normalized-conjugate identity and still calls field_simp. Reassociate the product and use the new conj_div_norm_mul helper, then close the remaining cast equality with Complex.ofReal_mul.
  • dead-leftover — LeanPool/CarlesonLT/Auto/ModelOperator.lean:6908
    The switch to linarith only leaves the hs bindings unused in abs_sub_semiCenter_le and suppBox_coord_lt. Remove both bindings so the proofs show which bounds they actually use.

Tokens: 2,728,022 in / 12,127 out · Tier: codex-subscription · Effort: xhigh · Billing: Codex subscription quota (no API credits) · Estimated cost: $11.0940 (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 432e18b 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