Invalidations caused by FixedPointNumbers and GeometryBasics

The FixedPointNumbers package is causing many invalidations, even though it does not engage in type piracy. For details, see: Loading FixedPointNumbers invalidates ~7,700 precompiled method instances (7x slower first mtkcompile) · Issue #331 · JuliaMath/FixedPointNumbers.jl · GitHub

My question: What is causing these invalidations? Should that be fixed in Julia itself, or in FixedPointNumbers, or is there no way to fix it?

I encounter this problem mainly when using GLMakie, which depends on FixedPointNumbers.

UPDATE: GeometryBasics has a similar problem: Loading GeometryBasics invalidates ~11,000 precompiled method instances (7x slower first mtkcompile) · Issue #284 · JuliaGeometry/GeometryBasics.jl · GitHub. Both issues must be fixed before loading GLMakie does not create long delays for MTK any more.

Might be case 4 mentioned in Type piracy · Aqua.jl, not explained like the others though. I know of invalidations where additional methods violate a prior assumption of a function only having a few (defaulting to 3 according to ?Base.Experimental.@max_methods) methods when abstract types are inferred for inputs, but a cursory glance at methods(-, Tuple{Real}) shows 9 in Base, so I doubt that assumption was made.

Probably unimportant, but I don’t see how the Union{} type described in case 3 and mentioned in the issue is practically relevant when nobody can instantiate it and won’t instantiate empty Union{}-parametric types, that is these call signatures aren’t worth compiling in the first place.

Julia v1.13 (v1.13.1) has been released. Updating the information on how the situation has changed might be helpful to developers.

As mentioned in Loading FixedPointNumbers invalidates ~7,700 precompiled method instances (7x slower first mtkcompile) · Issue #331 · JuliaMath/FixedPointNumbers.jl · GitHub, I suspect that SymbolicUtils.jl is partly to blame.
Of course, SymbolicUtils.jl might literally be the “victim”.

No improvement using Julia 1.13.1:

ufechner@framework:~/tmp$ julia --startup-file=no --project=. mwe.jl
mtkcompile: 0.04 s
ufechner@framework:~/tmp$ julia --startup-file=no --project=. mwe.jl
mtkcompile: 0.04 s
ufechner@framework:~/tmp$ LOAD_FPN=1 julia --startup-file=no --project=. mwe.jl
mtkcompile: 28.24 s
ufechner@framework:~/tmp$ LOAD_FPN=1 julia --startup-file=no --project=. mwe.jl
mtkcompile: 28.2 s

Thank you for updating the information.
Regarding the checked_mul issue in FixedPointNumbers v0.9, there are limits to what can be addressed within the package itself.
I have filed two issues regarding workarounds.

@ufechner7

SymbolicUtils.jl v4.50.0 has been released, incorporating:

How does it work when combined with FixedPointNumbers.jl v0.9.2?

Working much better now! I updated the issue for FixedPointNumbers.
Now we only need some progress with the invalidations caused by GeometryBasics.