Lake: per-module `*.setup.json` lists every transitive import and dominates build output on large projects
Prerequisites
- [x] Check that your issue is not already filed: https://github.com/leanprover/lean4/issues
- [x] Reduce the issue to a minimal, self-contained, reproducible test case. Avoid dependencies to Mathlib or Batteries.
- [x] Test your test case against the latest nightly release (4.38.0-nightly-2026-11-20, also v4.37.0-rc1).
- [ ] When reporting a perceived soundness bug: Does it affect
lake check --paranoid? N/A: not a soundness report.
Description
For each module Lake writes .lake/build/ir/<Module>.setup.json, and its importArts field has one entry per transitive import, with absolute paths. So the file grows with the module's import closure, and the total over a project grows with modules x closure size.
Context
I noticed this building a 175,187-module project on v4.33.1 (https://alpo.ge/lean.tar.gz.part01 ... part14), where most modules import Mathlib. After lake build the setup files were 983 GiB against 88 GiB of .olean files.
On a small scale: a module that only does import Mathlib gets a 6.2 MB setup file on v4.36.0 (6.4 MB on v4.37.0-rc1), next to a 5 KB .olean.
Steps to Reproduce
- Build a chain of 2,000 trivial modules with no dependencies, where module k imports module k-1:
mkdir repro && cd repro
echo 'leanprover/lean4:nightly' > lean-toolchain
cat > lakefile.toml <<'EOF'
name = "repro"
defaultTargets = ["Chain"]
[[lean_lib]]
name = "Chain"
EOF
mkdir Chain
printf 'def c0001 : Nat := 1\n' > Chain/M0001.lean
for k in $(seq 2 2000); do
printf 'import Chain.M%04d\n\ndef c%04d : Nat := c%04d + 1\n' $((k-1)) $k $((k-1)) > $(printf 'Chain/M%04d.lean' $k)
done
echo 'import Chain.M2000' > Chain.lean
lake build
- Compare the setup files with the compiled modules:
ls -l .lake/build/ir/Chain/M2000.setup.json .lake/build/lib/lean/Chain/M2000.olean
du -cb .lake/build/ir/Chain/*.setup.json | tail -1
du -cb .lake/build/lib/lean/Chain/*.olean | tail -1
Expected behavior: build output roughly proportional to the compiled modules.
Actual behavior (nightly): each .olean is 5,976 bytes, while M2000.setup.json is 184,036 bytes (1,999 entries, about 92 bytes each). The total is quadratic in the chain length:
| First n modules | all setup.json |
all .olean |
|---|---|---|
| 500 | 11.5 MB | 3.0 MB |
| 1,000 | 46.1 MB | 6.0 MB |
| 2,000 | 184.2 MB | 12.0 MB |
v4.37.0-rc1 behaves the same.
Versions
Lean 4.38.0-nightly-2026-11-20 (commit 82bff16a3463) and 4.37.0-rc1, Lake 5.0.0, Ubuntu 24.04 x86-64. The large project was on v4.33.1.
Additional Information
I don't know the constraints on the --setup format. Things that might work: storing a shared closure's artifact map once and referencing it, listing only direct imports, or deleting the file once the module is built.
Impact
Add :+1: to issues you consider important. If others are impacted by this issue, please ask them to add :+1: to it.