perf: speed up kernel typechecking of mathlib's slowest declarations#41705
Open
kbuzzard wants to merge 1 commit into
Open
perf: speed up kernel typechecking of mathlib's slowest declarations#41705kbuzzard wants to merge 1 commit into
kbuzzard wants to merge 1 commit into
Conversation
A profile of every declaration in mathlib found that kernel typechecking cost is extremely concentrated: 50 declarations out of 565,551 account for 6.8% of all kernel work. This fixes 14 of the worst 20 (the other 3 are being fixed in leanprover-community#41700, leanprover-community#41701 and leanprover-community#41664). In almost every case the declaration elaborates quickly but leaves a giant definitional unfolding for the kernel to redo without the elaborator's caching and lazy unfolding. Statements and definition values are unchanged throughout; only proofs are touched. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
PR summary cded8f6afdImport changes for modified filesNo significant changes to the import graph Import changes for all files
|
Member
Author
|
!radar |
|
Benchmark results for cded8f6 against b86f7b9 are in. There are significant results. @kbuzzard
Large changes (5✅)
Medium changes (4✅)
Small changes (1✅)
|
kbuzzard
commented
Jul 13, 2026
| -- simp? [-Functor.map_comp, ← assoc, hr] says: | ||
| simp only [← assoc, hr, id_comp, sub_self, zero_add] | ||
| simp [pullback.condition] | ||
| -- simp? [hcover, ← Functor.map_comp] says: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR golfs 14 of the 20 declarations in mathlib which are slowest to typecheck in the kernel. In every case (at least in all the ones I've checked) there was some kind of defeq abuse going on which the elaborator is quick to accept but which the kernel doesn't like, typically resulting in the unfolding of a large amount of stuff.
This is WIP for now because an LLM wrote all the code (including a bunch of comments) and I have not yet read it myself to check that the comments are accurate.