Lake: per-module `*.setup.json` lists every transitive import and dominates build output on large projects

オープン
#16,658 コメント 0 件 リアクション 2 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
22/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
json
領域
build-system

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

bug
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
  1. 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
  1. 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.

主要言語
Lean
スター
10.3k
フォーク
1.1k
平均マージ
19時間 8分
マージ済み PR(30日)
421

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

leanprover/lean4 のほかの issue

leanprover/lean4 の issue をすべて見る

似ている issue

Build System の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。