Skip to content

Reduce compiler memory in TwoColoringOneRound - #1039

Merged
Vilin97 merged 1 commit into
mainfrom
fix/two-coloring-compile-memory-20261126
Nov 26, 2026
Merged

Vilin97 merged 1 commit into
mainfrom
fix/two-coloring-compile-memory-20261126

Conversation

@Vilin97

@Vilin97 Vilin97 commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator

Ready for review. The clean project build took 11.32% less wall time and used 37.57% less peak anonymous memory per Lean compiler process.

Project and proof changes

I selected TwoColoringOneRound after reviewing the pinned source profile and a clean project build. Its 116 modules include several repeated finite checks. Intersection counting, symmetric orbit decomposition, and weak duality had the three highest compiler-memory peaks in the base build.

  • Derive row-match injectivity from the existing row and column bit lemmas. This replaces case splitting over 34 masks and three coordinates.
  • Verify the directed-orbit lookup once per directed index and check the two representatives of each variable. Use those facts in the existing characterization of the lookup.
  • Relate the finite multiplier sums to the certificate's array folds algebraically, factor the common denominator in the Frobenius sum, and extract stationarity directly from stationarityOK_true.

Declaration audit

Base 4d9a14617e2a00079cb44c86de6d3ffc099606f0. Lean 4.36.0 and Mathlib fc4f59e577feb1a4956671bc04ac18aaaf8cd842.

Before editing and after rebuilding, a standalone lake env lean --run inspector used Lean.readModuleDataParts on the exported, server, and private artifacts of all 116 modules. I compared the compressed manifests by module, artifact level, name, and kind, using structural representations of elaborated types, universe parameters, non-proof values, and kernel metadata. All 2,050 existing declarations matched, including generated equation lemmas. Six existing theorem proof bodies changed. Three private helper theorems and their three generated proof auxiliaries were added.

Measurements on the Azure VM

I removed only the project's Lake elaboration and IR outputs before each timed build, with dependency artifacts and the linter plugin already built. Both runs used taskset -c 8-15 lake --wfail --no-ansi build LeanPool.TwoColoringOneRound.Imports under GNU time. I sampled project Lean processes' RssAnon + VmSwap from /proc every 200 ms, using the same memory measure as the CI watchdog.

Metric Base Optimized
Clean project build wall time 100.79 s 89.38 s
Peak anonymous memory for one Lean compiler 859,528 KiB 536,640 KiB
Peak simultaneous anonymous memory across project compilers 2,369,664 KiB 2,340,824 KiB
GNU time maximum RSS 1,837,508 KiB 1,584,680 KiB

Lake reported 13 s → 2.4 s for IntersectionCounting, 12 s → 10 s for CorrAvgMatrixSymmDecompose, and 18 s → 8.1 s for WeakDuality in those runs. The corresponding sampled per-module peaks were 859,528 → 168,212 KiB, 776,032 → 536,640 KiB, and 659,020 → 487,984 KiB.

Synchronous Lean command profiling (-DElab.async=false -Dtrace.Elab.command=true -Dtrace.profiler=true -Dtrace.profiler.useHeartbeats=true) measured 73,958 → 171 heartbeats for rowMatch_maskAt_inj and 58,246 → 1,644 for varOfDirIdx_eq_some_iff including both new helpers, in the repository's maxHeartbeats units.

Validation

  • Clean build with warnings fatal and the repository proof-length plugin enabled.
  • Mathlib declaration lint via lake env lean --run scripts/ci/lint-project.lean <project modules> and text style via lake exe lint-style LeanPool.TwoColoringOneRound.Imports.
  • Repository static quality checks and project-scoped entry declaration, transitive axiom, option-manipulation, and compiler-log audits using lean_pool.quality.
  • lake exe mk_all --module --check, lake exe mk_all --check, and matching Lean/Mathlib pins for documentation preflight. I reviewed import suggestions for the three rebuilt modules with lake shake --force --keep-public.

Wall time is from one clean build per revision on the shared VM. The memory figures are sampled peaks. Local compiled validation covered this project, and GitHub CI covers the full pool.

@greptile-apps

greptile-apps Bot commented Nov 26, 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 defect was found in the proof refactor; the changed proofs preserve the existing contracts.RetriggerView in Greptile

[Low impact] No actionable defect was found in the proof refactor; the changed proofs preserve the existing contracts.

Summary

This PR replaces repeated finite checks with shared facts and algebraic proofs in three existing modules.

  • Intersection counting derives row-match injectivity from matching column facts.
  • The orbit lookup proves its rule using two reusable finite facts.
  • The weak-duality proof connects its sums to the certificate directly.

No actionable issues found. The reported build and memory improvements were not independently measured. External source and provenance claims were not independently verified; the locally recorded project claims, attribution, and theorem statements remain unchanged.

Reviews (1) · Last reviewed commit: "Reduce compiler memory in TwoColoringOne..." · Reviewed by Greptile

@github-actions

Copy link
Copy Markdown
Contributor

Proof profile (new / modified Lean files)

Statement changes

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

Also: 3 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 (3)
  • Distributed2Coloring.LowerBound.N1000000CorrAvgMatrixSymmDecompose.varOfDirIdx_orbitEntries — LeanPool/TwoColoringOneRound/LowerBound/N1000000CorrAvgMatrixSymmDecompose.lean
  • Distributed2Coloring.LowerBound.N1000000CorrAvgMatrixSymmDecompose.varOfDirIdx_pointsToOrbit — LeanPool/TwoColoringOneRound/LowerBound/N1000000CorrAvgMatrixSymmDecompose.lean
  • Distributed2Coloring.LowerBound.N1000000WeakDuality.sum_array_entries — LeanPool/TwoColoringOneRound/LowerBound/N1000000WeakDuality.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: 731,954 → 305,988 (-425,966, -58.2%). Commands: 173 → 176.

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

Files: 3 compared — 3 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/TwoColoringOneRound/LowerBound/N1000000WeakDuality.lean +31/-6 464,911 168,730 -296,181 -63.7% 41.02 17.63
LeanPool/TwoColoringOneRound/LowerBound/N1000000IntersectionCounting.lean +6/-1 119,985 46,651 -73,334 -61.1% 28.43 7.88
LeanPool/TwoColoringOneRound/LowerBound/N1000000CorrAvgMatrixSymmDecompose.lean +19/-2 147,059 90,607 -56,451 -38.4% 33.67 13.85
Total +56/-9 731,954 305,988 -425,966 -58.2% 103.1 39.4

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.

Approved on source at c6156bce. Required checks passed.

  • Proofs. Row-match injectivity follows from the existing row and column bit lemmas. The orbit lookup still checks both directions, using two smaller kernel-checked facts. Weak duality now relates its sums to the array folds and reads stationarity from the existing certificate theorem. The changed files retain their statements, definitions, and certificate data. Source diff
  • Compile cost. The reported sample shows an 11.3% reduction in clean project wall time and a 37.6% reduction in the peak for one Lean compiler process. The combined peak fell 1.2%. These memory figures come from one sampled build per revision. The independent CI profile shows 58.2% fewer heartbeats across the three files and no changed declaration types. The hosted build recompiled all three changed modules and passed lint and quality checks with cached dependencies. Proof Profile · Lean CI

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

Vilin97 commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator Author

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

Reviewed head: c6156bce9fd325a14155591d5acee93916c75bfa

Verdict: ✅ approve

The refactor derives row-match injectivity from existing mask lemmas, checks the orbit lookup in two directions, and uses algebraic identities and the existing stationarity certificate in weak duality. A local build with warnings treated as errors passed for all three changed modules and their downstream targets N1000000BCompressionForB and N1000000Bound. The clean-build memory figures come from the contributor’s measurements.

Aspect Value
Scope proof refactor for compile cost
Introduces tech debt ✅ no
Maintainability ✅ improved
Brittleness ✅ more_robust
Risk ✅ low

Explicit rewrites and separate table checks make failures easier to localize, and the PR’s proof profile reports 58.2% fewer elaboration heartbeats across the three changed modules.


Tokens: 2,424,766 in / 7,794 out · Tier: codex-subscription · Effort: xhigh · Billing: Codex subscription quota (no API credits) · Estimated cost: $9.8160 (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 9decab6 Nov 26, 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