Zulip Chat Archive

Stream: PR reviews

Topic: Speeding up Geometry/


Michael Rothgang (Jun 04 2024 at 13:14):

#13454, #13456, #13458, #13459 and #13497 each apply a few presumably-standard tricks to speed up the files in Geometry/Manifolds. Review is welcome.
One particular question: When making these improvements, I commented these declarations (and also ones which I could not speed up, though I wanted to): is some form of these (if any) worth preserving? I'll happily take these out if desired.

Patrick Massot (Jun 04 2024 at 17:39):

Thanks Michael. @Heather Macbeth did you see the sphere instance file in particular? I think it is a serious issue that those calculation-heavy file are so slow or so ugly depending on how much automation we use.

Patrick Massot (Jun 04 2024 at 17:40):

There are also lots of short-cut instances that hide issues we should probably work on. @Matthew Ballard did you see that?

Patrick Massot (Jun 04 2024 at 17:41):

Michael, could you make sure to create issues and clear annotations in the Lean code referring to those issues?

Heather Macbeth (Jun 05 2024 at 00:09):

I am a bit sad to see this (especially since the sphere file already got somewhat de-automated in the port). Is there a consensus that speedup is an intrinsic good? I think that there is real content conveyed by the statement that "this problem can be solved by simp with the standard simp-set" and this is lost when a simp is squeezed.

I'd also flag the field_simps and the convert .. using 1s in particular -- I don't really understand why these should be slow, we should have fast tactics for these tasks!

Kevin Buzzard (Jun 05 2024 at 05:10):

I think "field_simp is slow" is a known phenomenon but as far as I know nobody is working on it, even though we know some ways to speed it up (eg "don't just multiply by the product of all terms occurring to the right of a / sign, especially if several of them are powers or multiples of other ones")

Kim Morrison (Jun 05 2024 at 05:11):

I don't think it's even what field_simp is doing that is bad, it's the implementation that is bad. It is doing bad things with the simp discharger.

Michael Rothgang (Jun 05 2024 at 11:42):

Thanks for the comments! Let me respond to a few points:
First of all: I agree that ideally, adding short-cut instances, squeezing simps or avoid field_simp should not be necessary. I would also prefer living in a world where none of these were needed. That said, particularly Sphere and ContDiff/NormedSpace are really slow: that's beyond the point at which I can work on them nicely. I don't think this is a satisfactory state of affairs. I consider a temporary improvement which can be reverted once tactics have improved worth it.

I will happily file tracking issues for all these problems: slow nlinarith, slow field_simps and also the short-cut instances. (These are not close to all, by the way. There are enough remaining issues to be debugged :-))

Michael Rothgang (Jun 05 2024 at 11:42):

For field_simp in particular: the root fix is improving this tactic! (In fact, I was wondering how much effort this would be, and if I have a moment in the summer to work on this.) When this happens, my band-aid fixes should be taken out again.
In the mean-time, I personally think we should rather save the CI (and/or local development) time from not taking ages for a slow field_simp call.

Michael Rothgang (Jun 05 2024 at 11:43):

I was wondering: would using simp? says for all the changes help? At least, this documents the intent (which I agree is nice to preserve).

Michael Stoll (Jun 05 2024 at 11:46):

If I'm not mistaken, the simp? says syntax will be as slow as the original simp, so this would not help with speeding up things. I would think a comment to the effect "simp [minimal set of lemmas] can do this, but is slow" at the relevant points would allow to revert to the un-squeezed version whenever desired.

Johan Commelin (Jun 05 2024 at 11:48):

simp? says is only slow in CI, but not locally. tac1 says tac2 will run tac2 locally, but in CI it will run tac1 and check that it prints Try this: tac2.

Michael Stoll (Jun 05 2024 at 12:04):

So it's OK when working on a file, but misses the goal of speeding up CI.

Mauricio Collares (Jun 05 2024 at 12:49):

Michael Rothgang said:

That said, particularly Sphere and ContDiff/NormedSpace are really slow: that's beyond the point at which I can work on them nicely. I don't think this is a satisfactory state of affairs.

Did you test the bump/v4.9.0 branch? lean4#3636 might help, and 4.9.0-rc1 will probably be released in a few days.

Michael Rothgang (Jun 05 2024 at 13:15):

Mauricio Collares said:

Michael Rothgang said:

That said, particularly Sphere and ContDiff/NormedSpace are really slow: that's beyond the point at which I can work on them nicely. I don't think this is a satisfactory state of affairs.

Did you test the bump/v4.9.0 branch? lean4#3636 might help, and 4.9.0-rc1 will probably be released in a few days.

Not yet - I'll do so. Thanks for the pointer!

Matthew Ballard (Jun 12 2024 at 16:30):

Patrick Massot said:

There are also lots of short-cut instances that hide issues we should probably work on. Matthew Ballard did you see that?

Can someone point to a precise line and I can try to take a look?

Michael Rothgang (Jun 12 2024 at 17:38):

I guess the diff view in #13458 is a good start. Another option is line 81 in Instances/Sphere in #13456. (I cannot seem to permalink these, sorry.)
Also: thanks a lot for taking a look!

Matthew Ballard (Jun 12 2024 at 17:54):

The first local instance in #13458 is almost surely tripping synthPendingDepth

Matthew Ballard (Jun 12 2024 at 17:54):

Maybe the second also

Matthew Ballard (Jun 12 2024 at 18:05):

For #13456, making Submodule.span return a type a'la #12386 might help

Michael Rothgang (Aug 04 2024 at 13:51):

#13497 (squeezing very really slow field_simps in Geometry/Euclidean) is ready for review again
#15488 is a reduced version of #13456, and hopefully not controversial

Yaël Dillies (Aug 04 2024 at 13:51):

Could we put this energy into fixing field_simp itself, maybe?

Yaël Dillies (Aug 04 2024 at 13:52):

Oh sorry, I guess this was already discussed at length above

Michael Rothgang (Aug 04 2024 at 13:53):

This is just fixing up existing PRs; I agree to prioritise a field_simp rewrite over new PRs like this.


Last updated: May 02 2025 at 03:31 UTC