leanprover / leanprover/lean4

Importing a `Lean` module inflates binary size

Open
#5,274 1 comment 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug P-low
Dominant language
Lean
Stars
9.2k
Forks
990
Avg merge
1d 17h
Merged PRs (30d)
175

Description

Prerequisites

Please put an X between the brackets as you perform the following steps:

Description

The modules Lean.Data.AssocList, Lean.Data.Name, Lean.Data.LBool and Lean.Data.LOption are all very simple and do not import any non-prelude files. Still, importing any of these without using them causes the binary size to change from ~6M to ~86M. When copying the relevant file into the project and importing that instead, the blowup does not happen.

Context

There was some Zulip discussion a while ago, but there no one noticed that even importing a single file can lead to the blowup.

Steps to Reproduce

Start with the following file:

def main : IO Unit :=
  return ()
  1. Compile via lake build. Executable size is ~6.1M
  2. Add import import Lean.Data.AssocList and compile via lake build. Executable size is ~86M
  3. Copy Lean/Data/AssocList.lean into the project and import that instead. Compile via lake build. Executable size is ~6.1M

Expected behavior: Importing a tiny file and not using it should not inflate binary size.

Actual behavior: Importing a tiny file and not using it inflates binary size.

Versions
4.12.0-nightly-2024-09-05
Linux markus-z16 6.10.6-200.fc40.x86_64 #1 SMP PREEMPT_DYNAMIC Mon Aug 19 14:09:30 UTC 2024 x86_64 GNU/Linux
Impact

Add 👍 to issues you consider important. If others are impacted by this issue, please ask them to add 👍 to it.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the minimal main example with lake build, comparing the executable sizes for no import, import Lean.Data.AssocList, and a copied AssocList.lean. Inspect how these imports affect compilation and linking. Done means importing an unused tiny module no longer causes the reported binary-size increase.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.