Zulip Chat Archive

Stream: lean4

Topic: performance of large structures


Jakob von Raumer (Jan 21 2025 at 14:18):

Having a structure with lots of fields seems to have bad performance. Has anyone tried to tackle that issue? (/cc @Tobias Grosser @Léon Frenot )

Tobias Grosser (Jan 21 2025 at 14:19):

In which particular context? Do you have a lean only test case? Is there a lean pr?

Tobias Grosser (Jan 21 2025 at 14:20):

It would be useful to understand what the reason for this performance issue is.

Jakob von Raumer (Jan 21 2025 at 14:24):

HugeStructure.lean

Tobias Grosser (Jan 21 2025 at 14:29):

Are you saying just declaring the struct is slow?

Tobias Grosser (Jan 21 2025 at 14:29):

Is time to declare a struct non linear. I would find that surprising.

Jakob von Raumer (Jan 21 2025 at 14:32):

I haven't spent any thought on it. I wouldn't find it surprising if it was quadratic, since generally fields in structs can depend on the type of earlier fields

Henrik Böving (Jan 21 2025 at 14:35):

Almost all of the time is spent in [Meta.injective] [2.639434] Foo.mk ▶ according to the profiler

Tobias Grosser (Jan 21 2025 at 14:36):

What does this mean?

Henrik Böving (Jan 21 2025 at 14:37):

That lean spends almost all the time computing the injectivity theorems for the type

Jakob von Raumer (Jan 21 2025 at 14:39):

Ah yes.

Henrik Böving (Jan 21 2025 at 14:39):

Of course you could also try to merge these up into a big BitVec and just not care^^

Jakob von Raumer (Jan 21 2025 at 14:41):

Would prefer that over splitting up the structure :grinning_face_with_smiling_eyes:

Tobias Grosser (Jan 21 2025 at 14:42):

Interesting. I would check with growing examples if the asymptomatics are quadratic. If they are, there may be a faster algorithm.

Jakob von Raumer (Jan 21 2025 at 14:42):

Henrik Böving said:

That lean spends almost all the time computing the injectivity theorems for the type

So Foo.noConfusion itself also seems to have linear length, doesn't it?

Tobias Grosser (Jan 21 2025 at 14:43):

@jakob, do you already have an obvious mapping to bitvec mind.

Jakob von Raumer (Jan 21 2025 at 14:44):

Tobias Grosser said:

@jakob, do you already have an obvious mapping to bitvec mind.

-> other channel :grinning_face_with_smiling_eyes:

Sebastian Ullrich (Jan 21 2025 at 15:04):

We might want to consider generating the injectivity theorem lazily if e.g. you don't foresee needing it for your purposes, worth opening an issue

Jakob von Raumer (Jan 21 2025 at 15:12):

Do you think the generation is inherently quadratic?

Sebastian Ullrich (Jan 21 2025 at 15:43):

I'd have to take a closer look. I do see an option genInjectivity as well

Jakob von Raumer (Jan 21 2025 at 15:53):

That option makes it actually acceptably fast for our purposes

Jakob von Raumer (Jan 21 2025 at 15:59):

(But it still struggles with the above file...)

Kyle Miller (Jan 21 2025 at 16:29):

Can you quantify "bad performance" and "struggles"? From Henrik's comment it sounds like we're talking on the order of 5-10 seconds for a structure with over 5000 fields?

Kyle Miller (Jan 21 2025 at 16:31):

Ah, well I just gave it half a minute and it didn't finish elaboration, so get saying that Lean struggles with this one.

Henrik Böving (Jan 21 2025 at 16:33):

Kyle Miller said:

Can you quantify "bad performance" and "struggles"? From Henrik's comment it sounds like we're talking on the order of 5-10 seconds for a structure with over 5000 fields?

I cut out almost all the fields for the measurement :D


Last updated: May 02 2025 at 03:31 UTC