Skip to content

perf: skip native symbol lookups for interpreted modules - #16467

Merged
Kha merged 3 commits into
masterfrom
import-init-fastpaths
Nov 15, 2026
Merged

Kha merged 3 commits into
masterfrom
import-init-fastpaths

Conversation

@Kha

@Kha Kha commented Nov 14, 2026 •

Copy link
Copy Markdown
Member

This PR speeds up importing and interpreting code from modules that have no native code, such as those of most packages, by no longer looking up native initializers and symbols for them. On Mathlib, this reduces total build instructions by 2.9%.

The native initializer of a module references those of all its direct imports, so runInitAttrs now skips the initializer lookup for a module importing one without native code. The interpreter also no longer mangles and looks up the native symbols of non-extern declarations from such modules; loading a dynamic library resets this, as it may provide native code for them.

Kha and others added 2 commits November 14, 2026 17:00
`runInitAttrs` looked up the native initializers of every imported module, mangling two symbol names and calling `dlsym` for each in module mode. As the native initializer of a module references those of all its direct imports, a module importing one without native code cannot have native code either, so we now skip the lookup for it. On Mathlib this leaves only the modules directly above the natively compiled core.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
With `interpreter.prefer_native` (the default), the interpreter mangled the name of every called declaration and looked up its boxed and unboxed symbols with `dlsym`. `runInitAttrs` now records the imported modules it found to have no native code, and the interpreter skips the lookup for their non-`extern` declarations. Loading a dynamic library resets the record, as it may provide native code for such modules.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Kha Kha added the downstream Request a downstream-lean4 adaptation PR. label Nov 14, 2026
@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 Nov 14, 2026
@downstream-lean4

Copy link
Copy Markdown

The adaptation PR for this PR is leanprover/downstream-lean4#243.

@Kha
Kha marked this pull request as ready for review November 15, 2026 12:13
@Kha
Kha enabled auto-merge November 15, 2026 12:13
@Kha
Kha added this pull request to the merge queue Nov 15, 2026
Merged via the queue into master with commit 9180032 Nov 15, 2026
17 of 18 checks passed
@hargoniX
hargoniX deleted the import-init-fastpaths branch November 15, 2026 20:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

downstream Request a downstream-lean4 adaptation PR. 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.

1 participant