Repository navigation
Conversation
This extends the kernel fix from PR leanprover#12175 to the elaborator. In isDefEqDeltaStep.unfoldBoth, when comparing two plain constants with the same name but different universe parameters (e.g., c.{max u v} vs c.{max v u}), check if the universes are definitionally equal before unfolding. This avoids expensive unfolding when the terms are defeq modulo universe ordering. On the test case from leanprover#12102, this reduces elaboration time from 3.7M heartbeats to 7.3K heartbeats (499x speedup). Related: leanprover#12175 (kernel fix), leanprover#12102 (issue)
kim-em
force-pushed
the
kim/elab-universe-defeq-fix
branch
from
January 27, 2026 10:49
b35e845 to
81aee17
Compare
Collaborator
Author
|
!radar |
|
Benchmark results for 81aee17 against 42a0e92 are in! @kim-em
Small changes (1🟥)
|
Collaborator
|
Reference manual CI status:
|
ghost
pushed a commit
to leanprover-community/batteries
that referenced
this pull request
Jan 27, 2026
ghost
pushed a commit
to leanprover-community/mathlib4-nightly-testing
that referenced
this pull request
Jan 27, 2026
|
Mathlib CI status (docs):
|
kim-em
added a commit
that referenced
this pull request
Jan 27, 2026
When comparing two projections like `bar.toA` vs `bar.toA` where `bar` has universe `max u v` on one side and `max v u` on the other, check universe equality early before entering the isDefEqProjDelta loop. This is a more targeted optimization than #12186, which adds the check inside the delta reduction loop. By checking in the projection handler itself, we can potentially skip expensive work that happens before reaching the delta step. Related: #12102, #12186
kim-em
marked this pull request as draft
January 27, 2026 21:41
Collaborator
Author
|
Closing: this PR doesn't help the real Mathlib slowdown pattern (tested with KaehlerDifferential universe ordering issue). |
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 extends the kernel fix from #12175 to the elaborator.
In
isDefEqDeltaStep.unfoldBoth, when comparing two plain constants with the same name but different universe parameters (e.g.,c.{max u v}vsc.{max v u}), check if the universes are definitionally equal before unfolding. This avoids expensive unfolding when the terms are defeq modulo universe ordering.Performance
On the test case from #12102:
max u velabmax v uelabmax u vkernelmax v ukernelThis reduces elaboration time for the slow case from 3.7M to 7.3K heartbeats (499x speedup).
Note: The kernel is still slow because this PR only fixes the elaborator. Combined with #12175, both elaboration and kernel would be fast.
Related: #12175 (kernel fix), #12102 (issue)
🤖 Prepared with Claude Code