perf(RingTheory/Kaehler/JacobiZariski): reorder universe variables#21129
perf(RingTheory/Kaehler/JacobiZariski): reorder universe variables#21129
Conversation
PR summary 4466755c92Import changes for modified filesNo significant changes to the import graph Import changes for all files
Declarations diffNo declarations were harmed in the making of this PR! 🐙 You can run this locally as follows## summary with just the declaration names:
./scripts/declarations_diff.sh <optional_commit>
## more verbose report:
./scripts/declarations_diff.sh long <optional_commit>The doc-module for No changes to technical debt.You can run this locally as
|
|
!bench |
|
Here are the benchmark results for commit dbb8c6d. Benchmark Metric Change
=================================================================
+ ~Mathlib.RingTheory.Kaehler.JacobiZariski instructions -29.0% |
|
grunweg
left a comment
There was a problem hiding this comment.
Wow, these are great speed-ups! These should definitely land soon.
Do you understand why this changes performance? If so, it would be good to document (and look for other instances in mathlib/perhaps even write a linter). If not, can you start a discussion on zulip?
I'll be bold nominate for a quick merge, mostly to get the ball rolling.
maintainer delegate?
|
🚀 Pull request has been placed on the maintainer queue by grunweg. |
You probably missed the discussion at https://leanprover.zulipchat.com/#narrow/channel/144837-PR-reviews/topic/.2321099.20use.20unification.20hints.20for.20generators. So @mattrobball and @erdOne should have a look first. |
|
I think changing the convention for naming universes in this file is not a good idea. I am pretty sure that the kernel is able to check equality of levels from the names directly and that is what allows it avoid many unfolding steps. I am less sure about the importance of the ordering. |
It definitely matters that the universes of |
|
I should be clear since there are two possible orderings: 1. declaration ordering (ie what line number/column does a level appear) and 2. orderings on the names via the usual lexicographical ordering on strings. The former doesn't seem to matter. The latter seems to matter both for the elaborator and the kernel. Lexical ordering gives equality in the kernel. |
So what exactly do you suggest to change in this PR? |
|
I think it is possible to preserve the alphabetical order while having universe names adhering to the naming convention. |
mattrobball
left a comment
There was a problem hiding this comment.
These seem to give the same benefit and more closely follow the naming conventions in place.
This is very brittle though.
|
Aha, thanks for the clarification, changed it accordingly. |
|
!bench |
mattrobball
left a comment
There was a problem hiding this comment.
These would be better and still seem to perform the same. Generally, the user should not have to guess at the alphabetical orderings of names to get reasonable performance in elaboration and type checking.
| namespace Algebra | ||
|
|
||
| universe u₁ u₂ u₃ u₄ w' w u v uT | ||
| universe w₁ w₂ w₃ w₄ w₅ u₁ u₂ u₃ |
There was a problem hiding this comment.
| universe w₁ w₂ w₃ w₄ w₅ u₁ u₂ u₃ | |
| universe w₁ w₂ w₃ w₄ w₅ |
| variable {R : Type u₁} {S : Type u₂} [CommRing R] [CommRing S] [Algebra R S] | ||
| variable {T : Type u₃} [CommRing T] [Algebra R T] [Algebra S T] [IsScalarTower R S T] |
There was a problem hiding this comment.
| variable {R : Type u₁} {S : Type u₂} [CommRing R] [CommRing S] [Algebra R S] | |
| variable {T : Type u₃} [CommRing T] [Algebra R T] [Algebra S T] [IsScalarTower R S T] | |
| variable {R S T : Type*} [CommRing R] [CommRing S] [CommRing T] | |
| variable [Algebra R S] [Algebra R T] [Algebra S T] [IsScalarTower R S T] |
There was a problem hiding this comment.
Isn't this just working because the automatically introduced universe variables u_i are still alphabetically at the right place? So it seems this is even harder to control.
There was a problem hiding this comment.
Yes they are generated as u_i and we still need u < w for this hack. I don't see an advantage to the current situation and this is easier to digest for a reader.
Before merging, this PR will need some documentation with a link to an issue somewhere tracking this so readers won't have to guess at why things are the way they are.
There was a problem hiding this comment.
I personally think if we are intentionally controlling the names of universes we should be explicit about them.
| end Generators | ||
|
|
||
| variable {T : Type w} [CommRing T] [Algebra R T] [Algebra S T] [IsScalarTower R S T] | ||
| variable {T : Type u₃} [CommRing T] [Algebra R T] [Algebra S T] [IsScalarTower R S T] |
There was a problem hiding this comment.
| variable {T : Type u₃} [CommRing T] [Algebra R T] [Algebra S T] [IsScalarTower R S T] | |
| variable {T : Type*} [CommRing T] [Algebra R T] [Algebra S T] [IsScalarTower R S T] |
|
Is there an open issue on anything like this with core? |
|
Here are the benchmark results for commit 8700e71. Benchmark Metric Change
=================================================================
+ ~Mathlib.RingTheory.Kaehler.JacobiZariski instructions -29.1% |
|
|
I think I need to take a little time to evaluate this holistically. I am concerned we are papering over problems which will only become worse with time. |
|
I raise your 29% to 60% ;-) |
You did not follow the unwritten rules of this competition which clearly state without changing the results of this file. :) |
|
But I saved half a trillion instructions! That is a huge number! I've closed the PR in case anyone thought it was serious. How do we move forwards on this? Presumably someone needs to find some kind of example, ideally mathlib-free, showing where the problem is? This might be really hard. |
|
I am not sure that this PR is more serious than #21165. The latter does follow existing patterns in Mathlib. Given @kbuzzard 's comment I am becoming more skeptical that the current design is aligned with how Lean works, currently.
|
|
This has now come up in the triage meeting because it's one of the longest open PRs on the queue. One way of proceeding is that we document that this is a hack and merge it because at the end of the day it's making mathlib compile more quickly for everyone. What do people think about this? PS there doesn't seem to be a link to the relevant Zulip thread, which is here. |
|
I still worry we are just digging ourselves deeper into a hole with the current designs. |
|
This pull request has conflicts, please merge |
|
This PR has been migrated to a fork-based workflow: #26008 |
Naming of universe variables has an impact on universe unification. It seems to matter that the universe variables of
R,SandTappear before the universe variables of the generators in alphabetical order.