feat: look for .ilean.mmap files on watchdog load - #14421
Conversation
|
Mathlib CI status (docs):
|
|
Reference manual CI status:
|
Vtec234
left a comment
There was a problem hiding this comment.
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?
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. |
Comment about compactedIleanErrors > 0 warning.
|
|
||
| -- 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" |
There was a problem hiding this comment.
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.
This PR introduces a new, memory-mapped route to loading
ileanobjects 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.mmapfiles aside.ileanfiles one time, on watchdog start, and prefers the.ilean.mmapfile 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.mmapfiles, 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.mmapfiles in their.lakedirectories, 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):
.ilean.mmapfiles for just the.ileanfiles in Mathlib: watchdog needs 1.1G memory -> watchdog needs 496M memory.ilean.mmapfiles for all.ileanfiles, 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.)