Skip to content

Speed up HadwigerNelsonBounds certificate replay - #1025

Merged
Vilin97 merged 1 commit into
mainfrom
vilin/speed-up-hadwiger-nelson-certificates-20261125
Nov 25, 2026
Merged

Vilin97 merged 1 commit into
mainfrom
vilin/speed-up-hadwiger-nelson-certificates-20261125

Conversation

@Vilin97

@Vilin97 Vilin97 commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

Ready for review. The median clean build of HadwigerNelsonBounds took 21.4% less wall time.

Certificate replay

The 71-module project's source profile at ebaad62ab60d27fe11a5242fcbd7246d0d74d061 attributed 28.89 seconds of the 31.23-second PartsFirstStage recording to the 36 base-tree verifications. Those certificates already live in seven data modules. Each module now checks its own trees, giving Lake seven independent jobs. The existing indexed lemmas apply those checks through their original auxiliary declarations. Lean Pool source profile

The 31 hard-gadget proofs use decide +kernel. Lean's kernel checks the existing Boolean certificates, and the elaborator reuses the resulting proof without also reducing the decision procedure.

Declaration audit

PR base 67a81208bb92d879df07c7ce70b8580e55ee310a. The benchmark and baseline manifest were recorded at 981a0ba515543708bb42366028aacbf24642ff33. The intervening commit changed an independent project. The audited project and its build inputs match at both commits. A scratch Lean program used Lean.readModuleDataParts to serialize kernel declarations from the exported, server, and private oleans of all 71 modules. It compared elaborated expression trees, binder information, universe parameter lists, names, safety, reducibility hints, and definition values. The comparison ignores expression annotations and theorem proof terms.

All 2,164 original declaration names matched across the audited fields. Every original manifest record was present byte for byte. The 103 new declaration names comprise 36 base-tree lemmas and 67 decide +kernel proof auxiliaries.

Build measurements

Lean 4.36.0 and Mathlib fc4f59e577fe, on the same 16-vCPU Azure VM. Each run removed the project's output from .lake/build/lib/lean/LeanPool and .lake/build/ir/LeanPool and reused the dependency and linter-plugin builds. GNU time measured lake --no-ansi --wfail build +LeanPool.HadwigerNelsonBounds.Imports. All six runs rebuilt all 71 modules.

Measurement Base Optimized
Wall time, three runs 79.92 / 77.13 / 67.92 s 56.28 / 60.61 / 62.31 s
Median wall time 77.13 s 60.61 s
Median user CPU time 232.44 s 182.43 s
Median peak process RSS 2,780,916 KiB 2,779,160 KiB
Median Lake time for PartsFirstStage 20 s 9.2 s
Median Lake time for PartsGadgetHardVerification2 15 s 9.1 s

Wall time varied with load on the shared VM. The optimized median was 10.8% below the fastest measured baseline. The data modules now do their own verification work. The slowest of the seven took 4.6 seconds in the final run, up from 1.4 seconds for the slowest data module in the corresponding baseline run.

Local validation

  • Warning-free project builds using the configured Lean Pool compiler linter and --wfail.
  • lake env lean --run scripts/ci/lint-project.lean <71 project modules> and lake --wfail exe lint-style LeanPool.HadwigerNelsonBounds.Imports.
  • lake --wfail exe mk_all --module --check and PYTHONPATH=python python -m lean_pool.quality --repo . --static-only.
  • Lean Pool's project-scoped axiom, environment trust, compiler-message, and registered-declaration checks from lean_pool.quality.
  • PYTHONPATH=python python -m lean_pool.build_time_limits check --base 67a81208bb92d879df07c7ce70b8580e55ee310a --log ../candidate-3.log and git diff --check.
  • Import analysis used an up-to-date project build followed by lake shake --force --keep-public LeanPool.HadwigerNelsonBounds.Imports. Its suggestions were direct tactic import additions.

The timings and compiled-environment checks cover the selected project. Whole-pool validation runs in GitHub CI.

@greptile-apps

greptile-apps Bot commented Nov 25, 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 issue was found in this proof-only refactor.RetriggerView in Greptile

[Medium impact] No actionable issue was found in this proof-only refactor.

Summary

Moves 36 base-tree checks into seven independent certificate modules and switches 31 hard-gadget proofs to decide +kernel.

  • Base-tree checks run in the data modules that hold their trees.
  • Hard-gadget proofs use direct kernel checks for their certificates.

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

@github-actions

Copy link
Copy Markdown
Contributor

Proof profile (new / modified Lean files)

Statement changes

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

Also: 36 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 (36)
  • HadwigerNelsonBounds.partsBaseCertificate10_verifies — LeanPool/HadwigerNelsonBounds/PartsCertificateData0.lean
  • HadwigerNelsonBounds.partsBaseCertificate13_verifies — LeanPool/HadwigerNelsonBounds/PartsCertificateData0.lean
  • HadwigerNelsonBounds.partsBaseCertificate16_verifies — LeanPool/HadwigerNelsonBounds/PartsCertificateData0.lean
  • HadwigerNelsonBounds.partsBaseCertificate26_verifies — LeanPool/HadwigerNelsonBounds/PartsCertificateData0.lean
  • HadwigerNelsonBounds.partsBaseCertificate35_verifies — LeanPool/HadwigerNelsonBounds/PartsCertificateData0.lean
  • HadwigerNelsonBounds.partsBaseCertificate17_verifies — LeanPool/HadwigerNelsonBounds/PartsCertificateData1.lean
  • HadwigerNelsonBounds.partsBaseCertificate23_verifies — LeanPool/HadwigerNelsonBounds/PartsCertificateData1.lean
  • HadwigerNelsonBounds.partsBaseCertificate28_verifies — LeanPool/HadwigerNelsonBounds/PartsCertificateData1.lean
  • HadwigerNelsonBounds.partsBaseCertificate3_verifies — LeanPool/HadwigerNelsonBounds/PartsCertificateData1.lean
  • HadwigerNelsonBounds.partsBaseCertificate0_verifies — LeanPool/HadwigerNelsonBounds/PartsCertificateData2.lean
  • HadwigerNelsonBounds.partsBaseCertificate14_verifies — LeanPool/HadwigerNelsonBounds/PartsCertificateData2.lean
  • HadwigerNelsonBounds.partsBaseCertificate19_verifies — LeanPool/HadwigerNelsonBounds/PartsCertificateData2.lean
  • HadwigerNelsonBounds.partsBaseCertificate29_verifies — LeanPool/HadwigerNelsonBounds/PartsCertificateData2.lean
  • HadwigerNelsonBounds.partsBaseCertificate4_verifies — LeanPool/HadwigerNelsonBounds/PartsCertificateData2.lean
  • HadwigerNelsonBounds.partsBaseCertificate11_verifies — LeanPool/HadwigerNelsonBounds/PartsCertificateData3.lean
  • HadwigerNelsonBounds.partsBaseCertificate15_verifies — LeanPool/HadwigerNelsonBounds/PartsCertificateData3.lean
  • HadwigerNelsonBounds.partsBaseCertificate24_verifies — LeanPool/HadwigerNelsonBounds/PartsCertificateData3.lean
  • HadwigerNelsonBounds.partsBaseCertificate2_verifies — LeanPool/HadwigerNelsonBounds/PartsCertificateData3.lean
  • HadwigerNelsonBounds.partsBaseCertificate30_verifies — LeanPool/HadwigerNelsonBounds/PartsCertificateData3.lean
  • HadwigerNelsonBounds.partsBaseCertificate18_verifies — LeanPool/HadwigerNelsonBounds/PartsCertificateData4.lean
  • HadwigerNelsonBounds.partsBaseCertificate20_verifies — LeanPool/HadwigerNelsonBounds/PartsCertificateData4.lean
  • HadwigerNelsonBounds.partsBaseCertificate25_verifies — LeanPool/HadwigerNelsonBounds/PartsCertificateData4.lean
  • HadwigerNelsonBounds.partsBaseCertificate31_verifies — LeanPool/HadwigerNelsonBounds/PartsCertificateData4.lean
  • HadwigerNelsonBounds.partsBaseCertificate5_verifies — LeanPool/HadwigerNelsonBounds/PartsCertificateData4.lean
  • HadwigerNelsonBounds.partsBaseCertificate12_verifies — LeanPool/HadwigerNelsonBounds/PartsCertificateData5.lean
  • HadwigerNelsonBounds.partsBaseCertificate21_verifies — LeanPool/HadwigerNelsonBounds/PartsCertificateData5.lean
  • HadwigerNelsonBounds.partsBaseCertificate32_verifies — LeanPool/HadwigerNelsonBounds/PartsCertificateData5.lean
  • HadwigerNelsonBounds.partsBaseCertificate6_verifies — LeanPool/HadwigerNelsonBounds/PartsCertificateData5.lean
  • HadwigerNelsonBounds.partsBaseCertificate8_verifies — LeanPool/HadwigerNelsonBounds/PartsCertificateData5.lean
  • HadwigerNelsonBounds.partsBaseCertificate9_verifies — LeanPool/HadwigerNelsonBounds/PartsCertificateData5.lean
  • HadwigerNelsonBounds.partsBaseCertificate1_verifies — LeanPool/HadwigerNelsonBounds/PartsCertificateData6.lean
  • HadwigerNelsonBounds.partsBaseCertificate22_verifies — LeanPool/HadwigerNelsonBounds/PartsCertificateData6.lean
  • HadwigerNelsonBounds.partsBaseCertificate27_verifies — LeanPool/HadwigerNelsonBounds/PartsCertificateData6.lean
  • HadwigerNelsonBounds.partsBaseCertificate33_verifies — LeanPool/HadwigerNelsonBounds/PartsCertificateData6.lean
  • HadwigerNelsonBounds.partsBaseCertificate34_verifies — LeanPool/HadwigerNelsonBounds/PartsCertificateData6.lean
  • HadwigerNelsonBounds.partsBaseCertificate7_verifies — LeanPool/HadwigerNelsonBounds/PartsCertificateData6.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: 1,134,096 → 355,005 (-779,092, -68.7%). Commands: 142 → 178.

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

Files: 15 compared — 8 cheaper, 7 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/HadwigerNelsonBounds/PartsGadgetHardVerification2.lean +4/-4 228,091 47,522 -180,569 -79.2% 24.74 13.45
LeanPool/HadwigerNelsonBounds/PartsGadgetHardVerification4.lean +4/-4 154,639 32,183 -122,456 -79.2% 22.87 8.98
LeanPool/HadwigerNelsonBounds/PartsGadgetHardVerification7.lean +3/-3 154,026 31,989 -122,037 -79.2% 15.84 7.61
LeanPool/HadwigerNelsonBounds/PartsGadgetHardVerification1.lean +4/-4 153,605 31,978 -121,627 -79.2% 23.46 10.61
LeanPool/HadwigerNelsonBounds/PartsGadgetHardVerification0.lean +4/-4 153,349 31,934 -121,416 -79.2% 22.24 10.18
LeanPool/HadwigerNelsonBounds/PartsGadgetHardVerification6.lean +4/-4 152,980 31,844 -121,135 -79.2% 17.94 7.98
LeanPool/HadwigerNelsonBounds/PartsGadgetHardVerification5.lean +4/-4 80,510 16,634 -63,876 -79.3% 12.99 6.74
LeanPool/HadwigerNelsonBounds/PartsCertificateData5.lean +18/-0 7,260 22,131 +14,870 +204.8% 2.62 7.43
LeanPool/HadwigerNelsonBounds/PartsCertificateData6.lean +18/-0 7,515 21,939 +14,425 +192.0% 2.63 7.59
LeanPool/HadwigerNelsonBounds/PartsCertificateData0.lean +15/-0 7,367 20,928 +13,561 +184.1% 4.55 11.79
LeanPool/HadwigerNelsonBounds/PartsCertificateData4.lean +15/-0 7,261 20,810 +13,549 +186.6% 2.91 6.94
LeanPool/HadwigerNelsonBounds/PartsCertificateData1.lean +12/-0 7,393 17,253 +9,860 +133.4% 4.19 10.41
LeanPool/HadwigerNelsonBounds/PartsCertificateData3.lean +15/-0 7,266 16,226 +8,961 +123.3% 2.39 6.37
LeanPool/HadwigerNelsonBounds/PartsGadgetHardVerification3.lean +4/-4 5,607 994 -4,613 -82.3% 1.89 2.93
LeanPool/HadwigerNelsonBounds/PartsCertificateData2.lean +15/-0 7,227 10,639 +3,412 +47.2% 4.50 9.35
Total +139/-31 1,134,096 355,005 -779,092 -68.7% 165.8 128.4

New files — absolute profile

Total heartbeats: — maxHeartbeats units across 0 valid files (74 added LOC).

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

Count-heartbeats wall-clock total: 0.00 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/HadwigerNelsonBounds/PartsFirstStage.lean 74 — — — — — 168 1
Total 74 — 0.00 — — — 168 1

Aggregate phase totals

Phase Time
Unavailable —

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 at 46a605ec820e29da6e237cf53959b9aba374c7c4.

  • The seven data modules preserve their certificate payloads and each checks the trees it defines. The 36 forwarding proofs cover indices 0 through 35 and preserve the original lookup and public theorem. The eight hard-gadget files contain exactly 31 changes from decide to decide +kernel, keeping the same Boolean tests and Lean’s kernel check.
  • The optimizer’s clean builds report a median of 77.13 seconds before and 60.61 seconds after, and its compiled declaration audit retains all 2,164 original records across the compared fields. The hosted profile covers 15 comparable files and reports 68.7% fewer elaboration heartbeats. The data modules cost more individually because they now do the moved work. The profile could not measure the new first-stage imports against the old build. Exact-head Lean CI built them successfully and passed lint, quality, and timing checks. Hosted profile · Exact-head Lean CI

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

Vilin97 commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator Author

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

Reviewed head: 46a605ec820e29da6e237cf53959b9aba374c7c4

Verdict: ✅ approve

The refactor moves 36 base-tree checks into the seven modules that hold their certificates, so Lake can check them in parallel. The 31 hard-gadget proofs use decide +kernel to avoid reducing the same decision procedure twice. Both revisions rebuilt all 71 project modules with --wfail using the pinned dependency archives. In one run per revision, wall time fell from 49.9 s to 44.8 s and PartsFirstStage fell from 16 s to 7.2 s.

Aspect Value
Scope certificate replay and build parallelism
Introduces tech debt ✅ no
Maintainability ✅ improved
Brittleness ➖ unchanged
Risk ✅ low

Failed checks now point to the module that owns the certificate, and the downstream proofs retain explicit case dispatch and the same Boolean checkers.


Tokens: 1,571,985 in / 15,057 out · Tier: codex-subscription · Effort: xhigh · Billing: Codex subscription quota (no API credits) · Estimated cost: $6.5138 (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 ab1d140 Nov 25, 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