Lake: accumulate wide module import traces without quadratic prefix copies
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
Questa issue non è ancora stata valutata.
Descrizione
Lake's fetchImportInfo folds a Job.zipWith over a module's imports. Each
preceding job can still own its result when the next job adds two entries to
the import trace. In that case Array.push copies the existing prefix. For a
module with many direct imports the total copy work can grow quadratically.
Keep the two growing import traces' inputs in private reverse lists during the
fold. Update the hash in the original left-to-right order, take the same
maximum mtime, and keep the existing caption and nested traces. Convert each
list into an array in import order when the completed value is published. The
same job combinators still handle errors, cancellation, logs and job-state
traces.
Reproduction
The following Bash fixture uses only Lean and Lake. Run it from either a stock
Lean 4.36.0 installation or an SDK built at the same revision with the patch.
The first build primes the artifacts. Time subsequent no-op builds using
the same files, toolchain path, thread count and machine.
set -eu
dir=$(mktemp -d)
trap 'cd /; rm -rf -- "$dir"' EXIT
cd "$dir"
export LEAN_NUM_THREADS=8
cat >lakefile.toml <<'TOML'
name = "wide"
defaultTargets = ["Wide"]
[[lean_lib]]
name = "Wide"
TOML
mkdir Wide
printf 'module\n' >Wide.lean
for i in $(seq 1 2048); do
printf 'public import Wide.M%s\n' "$i" >>Wide.lean
printf 'module\n\npublic def m%s : Nat := %s\n' "$i" "$i" >"Wide/M$i.lean"
done
lake --offline --no-cache build
time -p lake --offline --no-cache build
Validation
On Lean 4.36.0, a stock warm build of the Mathlib umbrella (8,691 direct import
lines) recorded 25,441 non-exclusive trace array pushes with a prefix of at
least 512 elements. The calls processed 189,727,488 existing reference slots and
used 2.259 CPU seconds. This count includes both the import-info traces and the
job-state trace. The change here addresses the import-info traces.
A differential test compared all seven trace fields and direct artifacts
against the original fold over 4,096 import entries. It covered modules and
legacy sources, repeated providers, mixed visibility, meta and import-all
flags, and non-monotonic mtimes.
An end-to-end test against the stock Lean 4.36.0 release used a matched
Stage2 Release build containing this patch and the CRLF fast path. It used a
small project importing the full Mathlib umbrella at
fc4f59e577feb1a4956671bc04ac18aaaf8cd842, with dependencies prebuilt. Each
row below reports the means from a stock–candidate–candidate–stock sequence
on the same Linux x86-64 host with eight Lake threads.
| Workload | Metric | Stock | Combined candidate |
|---|---|---|---|
| Warm no-op | Elapsed time | 6.571 s | 5.030 s (23.5% lower) |
| Warm no-op | Lake CPU time | 13.380 s | 11.437 s (14.5% lower) |
| One-line edit | Time to first compiler fork | 6.523 s | 4.927 s (24.5% lower) |
| One-line edit | Elapsed time | 9.455 s | 7.813 s (17.4% lower) |
| Cold root module | Elapsed time | 9.104 s | 7.880 s (13.5% lower) |
These timings measure the combined candidate. Both SDKs generated
byte-identical traces and all seven compiler outputs for the root module and
for a separate rebuild of the Mathlib umbrella. The regenerated Mathlib
dependency hash also matched that of the prebuilt entry. A real mixed-import
fixture produced the same artifacts, and duplicate providers with distinct
definitions produced the same error, provider order, hashes, and exit code.
(Confirmed still present on master at 3158840c in src/lake/Lake/Build/Module.lean:477.)
- Lingua principale
- Lean
- Stelle
- 10.5k
- Fork
- 1.2k
- Merge medio
- 19h 36m
- PR unite (30g)
- 323
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di leanprover/lean4
-
P-medium
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
leanprover/lean4#16958 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
leanprover/lean4#16897 ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
leanprover/lean4#16892 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 1-3 ore Idoneità per principianti 86/100
leanprover/lean4#16886 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 78/100
leanprover/lean4#16820 ·
I maintainer di solito rispondono entro 1 giorno