Skip to content

feat: look for .ilean.mmap files on watchdog load - #14421

Open
robsimmons wants to merge 4 commits into
masterfrom
milean-small
Open

feat: look for .ilean.mmap files on watchdog load#14421
robsimmons wants to merge 4 commits into
masterfrom
milean-small

Conversation

@robsimmons

@robsimmons robsimmons commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

This PR introduces a new, memory-mapped route to loading ilean objects into memory. This feature should be treated as undocumented and subject to change without notice in future releases.

Lean4web and Workbench memory requirements are, at present, somewhat dominated by the watchdog's ileans. Mmapping ileans has a similar unshared-memory reduction to just deleting the ileans completely. (On live.lean-lang.org we've just deleted them, which slightly degrades the user experience.)

This design looks for .ilean.mmap files aside .ilean files one time, on watchdog start, and prefers the .ilean.mmap file if it has reports a last-modified time that is greater than or equal to the .ilean's last-modified time.

There's no mechanism for creating .ilean.mmap files, which is intentional: we only intend for this feature to be used for lean4web and workbench environments that we control at first so that we can back out of this design later on. (The robsimmons/milean repository shows one way of building these.) Unless someone goes out of their way to create .ilean.mmap files in their .lake directories, this PR adds the cost of one failed file lookup per ilean.

Benchmarking

These numbers were generated with a slightly different design, but the changes I've made shouldn't make a difference here.

In my benchmarking (on OSX, with a mathlib nightly-testing 2026-07-15 compiled against this branch):

  • Creating .ilean.mmap files for just the .ilean files in Mathlib: watchdog needs 1.1G memory -> watchdog needs 496M memory
  • Creating .ilean.mmap files for all .ilean files, including those in the core release: watchdog needs 1.1G memory -> watchdog needs 393M memory.

On Linux the effect is even more dramatic, taking us from 1.1G unshared memory for the watchdog to about 67M unshared memory for the watchdog. (This measurement includes the additional effect of 085ab16 — without that change, Linux unshared memory usage "only" goes down to about 171M.)

@github-actions github-actions Bot added the toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN label Jul 16, 2026
@mathlib-lean-pr-testing

mathlib-lean-pr-testing Bot commented Jul 16, 2026

Copy link
Copy Markdown

Mathlib CI status (docs):

  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase 52edefc40e92425b6bb2671c01420b7f76fb6caf --onto a4b639c5a1e545677b36b09a4770b7b559df805b. You can force Mathlib CI using the force-mathlib-ci label. (2026-07-16 18:44:10)
  • ✅ Mathlib branch lean-pr-testing-14421 has successfully built against this PR. (2026-07-16 20:19:28) View Log
  • ✅ Mathlib branch lean-pr-testing-14421 has successfully built against this PR. (2026-07-17 14:21:13) View Log
  • ✅ Mathlib branch lean-pr-testing-14421 has successfully built against this PR. (2026-07-19 12:53:05) View Log
  • ✅ Mathlib branch lean-pr-testing-14421 has successfully built against this PR. (2026-07-29 07:12:58) View Log
  • 💥 Mathlib branch lean-pr-testing-14421 build failed against this PR. (2026-07-29 20:32:02) View Log
  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase 7830144a18ea15cb4ec754508a87d259a4090f9c --onto 0bfc3acaef4ed0576307a77fbaa0c6e1a5dca402. You can force Mathlib CI using the force-mathlib-ci label. (2026-07-29 21:13:29)
  • ✅ Mathlib branch lean-pr-testing-14421 has successfully built against this PR. (2026-07-30 04:47:32) View Log
  • ✅ Mathlib branch lean-pr-testing-14421 has successfully built against this PR. (2026-07-30 15:40:19) View Log

@leanprover-bot

leanprover-bot commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator

Reference manual CI status:

  • ❗ Reference manual CI will not be attempted unless your PR branches off the nightly-with-manual branch. Try git rebase 52edefc40e92425b6bb2671c01420b7f76fb6caf --onto a4b639c5a1e545677b36b09a4770b7b559df805b. You can force reference manual CI using the force-manual-ci label. (2026-07-16 18:44:12)
  • ✅ Reference manual branch lean-pr-testing-14421 has successfully built against this PR. (2026-07-16 19:25:08) View Log
  • 🟡 Reference manual branch lean-pr-testing-14421 build against this PR didn't complete normally. (2026-07-16 19:27:26) View Log
  • ✅ Reference manual branch lean-pr-testing-14421 has successfully built against this PR. (2026-07-17 13:31:50) View Log
  • 🟡 Reference manual branch lean-pr-testing-14421 build against this PR didn't complete normally. (2026-07-17 13:33:39) View Log
  • ✅ Reference manual branch lean-pr-testing-14421 has successfully built against this PR. (2026-07-19 12:02:44) View Log
  • 🟡 Reference manual branch lean-pr-testing-14421 build against this PR didn't complete normally. (2026-07-19 12:04:04) View Log
  • ✅ Reference manual branch lean-pr-testing-14421 has successfully built against this PR. (2026-07-29 06:19:50) View Log
  • 🟡 Reference manual branch lean-pr-testing-14421 build against this PR didn't complete normally. (2026-07-29 06:20:08) View Log
  • 🟡 Reference manual branch lean-pr-testing-14421 build against this PR didn't complete normally. (2026-07-29 20:27:59) View Log
  • 💥 Reference manual branch lean-pr-testing-14421 build failed against this PR. (2026-07-29 20:29:10) View Log
  • ❗ Reference manual CI will not be attempted unless your PR branches off the nightly-with-manual branch. Try git rebase 7830144a18ea15cb4ec754508a87d259a4090f9c --onto a39eab69e1eee9ad38f4efe507907b1026a77808. You can force reference manual CI using the force-manual-ci label. (2026-07-29 21:13:31)
  • ✅ Reference manual branch lean-pr-testing-14421 has successfully built against this PR. (2026-07-30 03:58:53) View Log
  • 🟡 Reference manual branch lean-pr-testing-14421 build against this PR didn't complete normally. (2026-07-30 04:00:13) View Log
  • ✅ Reference manual branch lean-pr-testing-14421 has successfully built against this PR. (2026-07-30 14:49:46) View Log
  • 🟡 Reference manual branch lean-pr-testing-14421 build against this PR didn't complete normally. (2026-07-30 14:51:54) View Log

@github-actions github-actions Bot added the mathlib4-nightly-available A branch for this PR exists at leanprover-community/mathlib4-nightly-testing:lean-pr-testing-NNNN label Jul 16, 2026
@leanprover-bot leanprover-bot added the builds-manual CI has verified that the Lean Language Reference builds against this PR label Jul 16, 2026
@mathlib-lean-pr-testing mathlib-lean-pr-testing Bot added the builds-mathlib CI has verified that Mathlib builds against this PR label Jul 16, 2026
@robsimmons
robsimmons marked this pull request as ready for review July 17, 2026 12:55
@robsimmons
robsimmons requested a review from mhuisi as a code owner July 17, 2026 12:55
mathlib-nightly-testing Bot pushed a commit to leanprover-community/batteries that referenced this pull request Jul 17, 2026
mathlib-nightly-testing Bot pushed a commit to leanprover-community/mathlib4-nightly-testing that referenced this pull request Jul 17, 2026
leanprover-bot added a commit to leanprover/reference-manual that referenced this pull request Jul 17, 2026
@robsimmons robsimmons added the changelog-no Do not include this PR in the release changelog label Jul 17, 2026
mathlib-nightly-testing Bot pushed a commit to leanprover-community/batteries that referenced this pull request Jul 19, 2026
mathlib-nightly-testing Bot pushed a commit to leanprover-community/mathlib4-nightly-testing that referenced this pull request Jul 19, 2026
leanprover-bot added a commit to leanprover/reference-manual that referenced this pull request Jul 19, 2026
@robsimmons
robsimmons requested a review from Vtec234 July 24, 2026 21:44

@Vtec234 Vtec234 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On Linux the effect is even more dramatic, taking us from 1.1G unshared memory for the watchdog to about 67M unshared memory for the watchdog.

Do you know why the unshared amount is larger on macOS?

Comment thread src/Lean/Server/References.lean Outdated
Comment thread src/Lean/Server/References.lean Outdated
Comment thread src/Lean/Server/References.lean Outdated
Comment thread src/Lean/Server/Watchdog.lean Outdated
@robsimmons

Copy link
Copy Markdown
Contributor Author

Do you know why the unshared amount is larger on macOS?

No, but I believe it has to do with larger minimum page size and the fact that we are loading thousands of sometimes tiny little files.

@robsimmons
robsimmons requested a review from Vtec234 July 29, 2026 05:49
mathlib-nightly-testing Bot pushed a commit to leanprover-community/batteries that referenced this pull request Jul 29, 2026
mathlib-nightly-testing Bot pushed a commit to leanprover-community/mathlib4-nightly-testing that referenced this pull request Jul 29, 2026
leanprover-bot added a commit to leanprover/reference-manual that referenced this pull request Jul 29, 2026
Comment thread src/Lean/Server/References.lean Outdated
Comment thread src/Lean/Server/References.lean Outdated
@mathlib-lean-pr-testing mathlib-lean-pr-testing Bot added breaks-mathlib This is not necessarily a blocker for merging: but there needs to be a plan and removed builds-mathlib CI has verified that Mathlib builds against this PR labels Jul 29, 2026
@github-actions github-actions Bot removed the changes-stage0 Contains stage0 changes, merge manually using rebase label Jul 29, 2026
mathlib-nightly-testing Bot pushed a commit to leanprover-community/batteries that referenced this pull request Jul 30, 2026
leanprover-bot added a commit to leanprover/reference-manual that referenced this pull request Jul 30, 2026
mathlib-nightly-testing Bot pushed a commit to leanprover-community/mathlib4-nightly-testing that referenced this pull request Jul 30, 2026
@leanprover-bot leanprover-bot added builds-manual CI has verified that the Lean Language Reference builds against this PR and removed breaks-manual This is not necessarily a blocker for merging, but there needs to be a plan. labels Jul 30, 2026
@mathlib-lean-pr-testing mathlib-lean-pr-testing Bot added builds-mathlib CI has verified that Mathlib builds against this PR and removed breaks-mathlib This is not necessarily a blocker for merging: but there needs to be a plan labels Jul 30, 2026
Comment about compactedIleanErrors > 0 warning.
Comment on lines +1715 to +1719

-- This warning message only makes sense if we're only building .ilean.mmap files for read-only toolchain and library files.
-- For other use cases, this will be too noisy.
if compactedIleanErrors > 0 then
(← getStderr).putStrLn s!"Attempted to load {compactedIleanCount} .{Ilean.compactedExt} {compactedIleanCount.plural "file"}, but failed to load {compactedIleanErrors} of them"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would be happy to simplify this PR even further by removing this error reporting — but given the intended workbench use case of generated .ilean.mmap files for read-only toolchain and library files, I thought the warning was prudent.

mathlib-nightly-testing Bot pushed a commit to leanprover-community/batteries that referenced this pull request Jul 30, 2026
mathlib-nightly-testing Bot pushed a commit to leanprover-community/mathlib4-nightly-testing that referenced this pull request Jul 30, 2026
leanprover-bot added a commit to leanprover/reference-manual that referenced this pull request Jul 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

builds-manual CI has verified that the Lean Language Reference builds against this PR builds-mathlib CI has verified that Mathlib builds against this PR changelog-no Do not include this PR in the release changelog mathlib4-nightly-available A branch for this PR exists at leanprover-community/mathlib4-nightly-testing:lean-pr-testing-NNNN toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants