Description
This makes me sad:
julia> using SnoopCompileCore
julia> invs = @snoopr using ColorTypes;
julia> using SnoopCompile
julia> length(uinvalidated(invs))
396
That's quite a large number. But it gets worse when you see what gets invalidated:
julia> trees = invalidation_trees(invs)
2-element Vector{SnoopCompile.MethodInvalidations}:
inserting (::Type{var"#s2"} where var"#s2"<:FixedPointNumbers.FixedPoint)(x::AbstractChar) in FixedPointNumbers at /home/tim/.julia/packages/FixedPointNumbers/HAGk2/src/FixedPointNumbers.jl:60 invalidated:
backedges: 1: superseding (::Type{T})(x::AbstractChar) where T<:Union{AbstractChar, Number} in Base at char.jl:50 with MethodInstance for (::Type{K} where K<:Char)(::Char) (2 children)
8 mt_cache
inserting convert(::Type{C}, c::Colorant) where C<:Colorant in ColorTypes at /home/tim/.julia/packages/ColorTypes/RF8lb/src/conversions.jl:73 invalidated:
backedges: 1: superseding convert(::Type{Union{}}, x) in Base at essentials.jl:203 with MethodInstance for convert(::Type{Union{}}, ::Any) (622 children)
julia> tree = trees[end]
inserting convert(::Type{C}, c::Colorant) where C<:Colorant in ColorTypes at /home/tim/.julia/packages/ColorTypes/RF8lb/src/conversions.jl:73 invalidated:
backedges: 1: superseding convert(::Type{Union{}}, x) in Base at essentials.jl:203 with MethodInstance for convert(::Type{Union{}}, ::Any) (622 children)
julia> root = tree.backedges[1]
MethodInstance for convert(::Type{Union{}}, ::Any) at depth 0 with 622 children
julia> ascend(root)
Choose a call for analysis (q to quit):
> convert(::Type{Union{}}, ::Any)
convert(::Type{Nothing}, ::Any)
setindex!(::IdDict{Dict{String, Any}, Nothing}, ::Any, ::Any)
push!(::Base.IdSet{Dict{String, Any}}, ::Dict{String, Any})
parse_array_table(::Base.TOML.Parser)
parse_table(::Base.TOML.Parser)
parse_toplevel(::Base.TOML.Parser)
tryparse(::Base.TOML.Parser)
parse(::Base.TOML.Parser)
...
This immediately hits parse(::Base.TOML.Parser)
, and thus we're back to invalidating the code that Julia uses to load other packages. Hence using
is slower than it was earlier in the 1.6 dev cycle. I thought I'd felt some of that just in ordinary usage, but not until I looked were my vague suspicions confirmed.
That ColorTypes signature, convert(::Type{C}, c::Colorant) where C<:Colorant
, is remiscent of the kind of work @vtjnash did on ambiguities and invalidation in #36863 and #36733, and the signatures seem ambiguous to me (Union{}
is more specialized than C<:Colorant
, whereas Any
is less specialized than Colorant
.) Does this need a fresh look?