Repository navigation
Speed up DistinctDistances by reusing checked row summaries - #1028
Conversation
|
Advisory cross-file review against Lean Pool's supervisory rubric. This is not by itself a significance, source-verification, or merge verdict. [Medium impact] No actionable defect was found in this proof-only refactor. SummaryThe PR checks three long rows once, then reuses their packed summaries in 46 certificate proofs.
Reviews (1) · Last reviewed commit: "Reuse checked geometric row summaries in..." · Reviewed by Greptile |
Vilin97
left a comment
There was a problem hiding this comment.
Accept the cached certificate replay at a7869ff, pending required CI.
- The shared replay proves equality with the original checker for arbitrary rational endpoints and weighted trees. It checks the index bounds before scaling the long rows. An interval row can reuse its coefficients only when the checked denominator permits replacing the right-hand side. Other cases still use the original checker.
- I verified that all 46 certificate modules are byte-identical after removing the cache import and restoring the prior proof expression. The certificate data, theorem statements, final validity check, and project card stay the same.
- The paired clean build reported 36.92% less wall time and 34.20% less CPU time, including the cost of building the new cache module. The source combines cleanly with current main.
Proof profile (new / modified Lean files)
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 368 tracked declarations across 47 modified files kept their type; only proofs / definition bodies changed. Also: 46 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 (46)
Statements are compared textually against the merge base (comments and whitespace ignored; Total heartbeats: 279,042 maxHeartbeats units across 1 valid file (725 added LOC). Sum of Count-heartbeats wall-clock total: 43.37 s. Repeated import cost inside Heartbeat values sum disjoint root command traces with LOC counts added lines in the profiled Lean files from this PR diff.
Aggregate phase totals
Slowest changed modules (from
|
| Changed module | Lake time |
|---|---|
LeanPool.DistinctDistances.S4CertificateCachedRows |
46.00 s |
Per-file `lean --profile` output
LeanPool/DistinctDistances/S4CertificateCachedRows.lean
import took 3.04s
tactic execution of Lean.Parser.Tactic.change took 339ms
type checking took 5.11s
type checking took 5.27s
type checking took 5.18s
type checking took 4.3s
type checking took 4.57s
type checking took 4.55s
type checking took 3.07s
type checking took 2.94s
type checking took 3.86s
cumulative profiling times:
attribute application 0.25ms
blocked (unaccounted) 60.4s
compilation (IR) 0.0763ms
compilation (LCNF base) 0.475ms
compilation (LCNF impure) 0.282ms
compilation (LCNF mono) 0.57ms
congr simp thm 2.55ms
declTypeLinter 8.58ms
elaboration 60.3ms
fix level params 0.622ms
import 3.04s
initialization 31.3ms
instantiate metavars 1.78ms
interpretation 434ms
let-to-have transformation 0.654ms
linting 22.7ms
module linting 0.0306ms
parsing 18.1ms
process pre-definitions 8.53ms
share common exprs 3.52ms
simp 29.7ms
tactic execution 514ms
tacticAnalysis 7.25ms
type checking 38.9s
typeclass inference 19.6ms
real 43.22
user 40.56
sys 1.29
Advisory only — never blocks merge. Full log uploaded as the proof-profile artifact.
🤖 LLM review — refactor (
|
| Aspect | Value |
|---|---|
| Scope | certificate replay caching |
| Introduces tech debt | 🛑 yes |
| Maintainability | 🛑 regressed |
| Brittleness | 🛑 more_brittle |
| Risk | 🟡 medium |
A change to the first case’s upper endpoint can break the shared cache build for every caller, including subtrees of unrelated cases.
Findings (2)
- brittle-cache-anchor —
LeanPool/DistinctDistances/S4CertificateCachedRows.lean:249
upperDenominatorrequires the full row denominator atcaseY.get 1to equal the coefficient denominator. A Lean probe confirmed that a small perturbation triples the full denominator and takes the fallback when passed to replay. Putting that endpoint in the case table would fail the shared proof before any caller could use the fallback. Generate and check both interval caches with a fixed zero right-hand side so case-table edits can use the existing fallback. - prompt-injection — PR-wide
The advisory PR comment repeats its no-defect verdict in hidden HTML<rp>fallback text, where automated reviewers can see it. Remove the hidden copy of the verdict.
Tokens: 5,324,139 in / 20,315 out · Tier: codex-subscription · Effort: xhigh · Billing: Codex subscription quota (no API credits) · Estimated cost: $21.6013 (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.
request_changes is an ask, not a close: of the reviewer's past request_changes verdicts, 39% were merged after a human looked. Read the findings before acting on the verdict.
Ready for review. DistinctDistances builds 36.92% faster and its peak sampled anonymous compiler memory is 23.98% lower on the Azure VM.
Change
The Lean 4.36 source profile for the 254-module DistinctDistances project showed several certificate modules spending 17–23 seconds in frontend work. Forty-six subtree proofs revisit the long moment and interval rows derived from the same 1,283-point grid.
The new replay verifies the packed summaries of those three rows at unit weight once. A Lean proof shows that multiplying the packed chunks gives exactly the original weighted tries, and checked index bounds justify scaling the cost. For each interval row, the proof checks its common coefficient denominator and shows when a new endpoint can be handled by changing just the right-hand side. Other rows and denominators use the original evaluator.
Declaration audit
Base
a87d4847f3013d5b52180931046f360bfb0416a3and heada7869ff5541a48b2a32c8820c20971407cdd5e51were audited with Lean's.oleanreader across the exported, server, and private layers. The compressed manifests record owner, name, layer, universe parameters, kind, safety, reducibility, exact structural kernel types, and non-theorem values. The kernel checked the regenerated proof bodies.All 3,898 original declarations and 11,224 original manifest records matched, including generated private proof declarations. The 136 additional declarations belong to the shared cache and the 46 cached subtree proofs.
Measurements
Each run rebuilt every project module from empty project build outputs using the same prebuilt pinned dependencies and linter plugin. The VM used CPUs 12–15 and
LEAN_NUM_THREADS=6, with Lean v4.36.0 and Mathlibfc4f59e577feb1a4956671bc04ac18aaaf8cd842.The new module's 50-second clean build is included in the totals. Case 03 subtree 3 went from 49 s to 26 s, case 09 subtree 1 from 48 s to 26 s, and case 22 subtree 1 from 61 s to 14 s. This was one paired clean build on a shared VM. Lake's module times include overlapping jobs.
Validation
The warning-free project build, Mathlib declaration linters, style check, repository static quality checks, project declaration and axiom audits, compiled-environment and compiler-message audits, generated indexes, and per-file resource checks passed. The added module used 1,105,100 KiB of sampled anonymous RSS in the timed build and also passed a separate rebuild under the repository's 3 GiB watchdog. The import diagnostic reported redundant imports throughout the project. The edited proofs keep their explicit replay tactic dependency.