You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Loading GeometryBasics into a session that already has ModelingToolkit loaded invalidates 11,182 precompiled method instances and makes the first mtkcompile call take 15.8 s instead of 2.2 s — a 7x slowdown in a script that never uses a geometric type.
Most users meet this indirectly: Makie depends on GeometryBasics, so any Makie-based
plotting next to ModelingToolkit pays this cost on the first model build.
MWE
# mwe.jlusing ModelingToolkit
using ModelingToolkit: t_nounits as t, D_nounits as D
ifget(ENV, "LOAD_GB", "0") =="1"@evalusing GeometryBasics # <-- the only differenceend@variablesx(t)=1.0y(t)=0.0@named sys =System([D(x) ~ y, D(y) ~-x], t)
t0 =time(); mtkcompile(sys); println("mtkcompile: ", round(time()-t0, digits=2), " s")
$ julia --startup-file=no --project=. mwe.jl
mtkcompile: 2.22 s
$ LOAD_GB=1 julia --startup-file=no --project=. mwe.jl
mtkcompile: 15.80 s
As a control, loading a package of comparable size that does not add methods to Base
generics (using LaTeXStrings) leaves the time unchanged at 2.23 s, so this is not the
general cost of loading a package.
Attribution
using SnoopCompileCore
using ModelingToolkit
invs =@snoop_invalidationsusing GeometryBasics;
using SnoopCompile
length(uinvalidated(invs)) # 11182, from 169 culprit methods
Ranked by countchildren:
children
method
19704
convert(::Type{O}, x::Integer) where O<:OffsetInteger — src/offsetintegers.jl:55
6542
convert(::Type{IT}, x::OffsetInteger) where IT<:Integer — src/offsetintegers.jl:53
promote_rule(::Type{OffsetInteger{O1,T1}}, ::Type{OffsetInteger{O2,T2}}) where {O1,O2,T1<:Integer,T2<:Integer} — src/offsetintegers.jl:87
566
promote_rule(::Type{IT}, ::Type{<:OffsetInteger}) where IT<:Integer — src/offsetintegers.jl:85
412
broadcasted(f, a::AbstractArray{T}, b::NgonFace) where T<:NgonFace — src/fixed_arrays.jl:124
Nearly all of it comes from OffsetInteger. convert(::Type{IT}, ::OffsetInteger) where IT<:Integer in particular is a method on Base.convert whose second argument carries the
package's own type but whose first is a broad Type{IT<:Integer}, which discards inference
results in already-loaded packages that call convert(::Type{<:Integer}, x) on
non-concrete argument types.
Question
Is OffsetInteger still load-bearing, and if so, is there room to narrow these signatures?
I am mostly filing this for the record, since the measured impact is large and I could not
find an existing issue about it. Happy to run further measurements if that helps.
Versions
Julia 1.12.7 (Linux, x86_64), GeometryBasics 0.5.12, ModelingToolkit 11.17.0,
SnoopCompile 3.2.9.
Yes, OffsetInteger is sadly still "load bearing"...
I guess we may be able to do a refactor to make it less impactful, but I actually already spend considerable time on this and it's not easy.
I think it will only be possible to improve this in Julia, or by completely rethinking how we can store 0 based indices and work with them like normal julia indices.
To be fair, its mainly used as a storage format, so I dont think that much code actually depends on julia_array[offset_integer].
Maybe we could even remove the convert + >=, without too much breakage.
Activity
kimikage commentedon Sep 27, 2026
xref: https://discourse.julialang.org/t/invalidations-caused-by-fixedpointnumbers/139232
SimonDanisch commentedon Sep 28, 2026
Yes, OffsetInteger is sadly still "load bearing"...
I guess we may be able to do a refactor to make it less impactful, but I actually already spend considerable time on this and it's not easy.
I think it will only be possible to improve this in Julia, or by completely rethinking how we can store 0 based indices and work with them like normal julia indices.
To be fair, its mainly used as a storage format, so I dont think that much code actually depends on
julia_array[offset_integer].Maybe we could even remove the
convert+>=, without too much breakage.