Lake: per-module `*.setup.json` lists every transitive import and dominates build output on large projects
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 22/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- json
- Domain
- build-system
Research direction
Start with the reproduction: a chain of 2,000 trivial modules where each .lake/build/ir/Chain/M<k>.setup.json has an importArts list with one entry per transitive import, so the total size grows quadratically. Look at how Lake writes this file and what the --setup consumer reads from it. Done means the setup file size stops scaling with the import closure, and the chain repro's total setup.json output is roughly proportional to the module count. Agreeing on the format change first is part of the work.
Written by the indexing model from the issue text.
Description
Prerequisites
- Check that your issue is not already filed:
https://github.com/leanprover/lean4/issues - Reduce the issue to a minimal, self-contained, reproducible test case.
Avoid dependencies to Mathlib or Batteries. - 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 👍 to issues you consider important. If others are impacted by this issue, please ask them to add 👍 to it.
- Dominant language
- Lean
- Stars
- 10.3k
- Forks
- 1.1k
- Avg merge
- 19h 8m
- Merged PRs (30d)
- 421
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from leanprover/lean4
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
leanprover/lean4#16681 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
leanprover/lean4#16305 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
leanprover/lean4#16299 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
leanprover/lean4#16257 ·
Maintainers usually reply within 1 day
-
`IO.FS.realPath` reports every failure as `noFileOrDirectory` instead of classifying by `errno`Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
leanprover/lean4#15683 ·
Maintainers usually reply within 1 day
All issues in leanprover/lean4
Similar issues
-
sync cache dist/imgOpen
Difficulty 1/5 Under an hour Newbie friendliness 82/100
oleeskild/digitalgarden#435 ·
-
enhancement
Difficulty 1/5 Under an hour Newbie friendliness 78/100
Tarektouati/made#186 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
fluentmigrator/fluentmigrator#2463 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
jenkins-infra/packer-images#3314 · 4 comments ·
Maintainers usually reply within 1 day