-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Loading CSV.jl makes conversion of a Some{Any} to a Some{Any} 200 times slower #31535
Comments
On master it's slightly different but same outcome: julia> c = Some{Any}("foo")
Some("foo")
julia> @code_warntype convert(Some{Any}, c)
Variables
#self#::Core.Compiler.Const(convert, false)
#unused#::Core.Compiler.Const(Some{Any}, false)
x::Some{Any}
Body::Some{Any}
1 ─ %1 = Core.apply_type(Base.Some, $(Expr(:static_parameter, 1)))::Core.Compiler.Const(Some{Any}, false)
│ %2 = $(Expr(:static_parameter, 1))::Core.Compiler.Const(Any, false)
│ %3 = Base.getproperty(x, :value)::Any
│ %4 = Base.convert(%2, %3)::Any
│ %5 = (%1)(%4)::Some{Any}
└── return %5
julia> m = @which convert(Some{Any}, c)
convert(::Type{Some{T}}, x::Some) where T in Base at some.jl:18
julia> m.specializations
Core.TypeMapEntry(nothing, Tuple{typeof(convert),Type{Some{Any}},Some{Any}}, nothing, svec(), 25990, -1, MethodInstance for convert(::Type{Some{Any}}, ::Some{Any}), false, true, false)
julia> using BenchmarkTools
julia> @btime convert(Some{Any}, $c)
3.656 ns (1 allocation: 16 bytes)
Some("foo")
julia> length(methods(Base.getproperty))
21
julia> length(methods(Base.convert))
187
julia> using CSV
julia> @code_warntype convert(Some{Any}, c)
Variables
#self#::Core.Compiler.Const(convert, false)
#unused#::Core.Compiler.Const(Some{Any}, false)
x::Some{Any}
Body::Some{Any}
1 ─ %1 = Core.apply_type(Base.Some, $(Expr(:static_parameter, 1)))::Core.Compiler.Const(Some{Any}, false)
│ %2 = $(Expr(:static_parameter, 1))::Core.Compiler.Const(Any, false)
│ %3 = Base.getproperty(x, :value)::Any
│ %4 = Base.convert(%2, %3)::Any
│ %5 = (%1)(%4)::Some{Any}
└── return %5
julia> m == @which convert(Some{Any}, c)
true
julia> m.specializations
Core.TypeMapEntry(Core.TypeMapEntry(nothing, Tuple{typeof(convert),Type{Some{Any}},Some{Any}}, nothing, svec(), 8030, 26005, MethodInstance for convert(::Type{Some{Any}}, ::Some{Any}), false, true, false), Tuple{typeof(convert),Type{Some{Any}},Some{Any}}, nothing, svec(), 26027, -1, MethodInstance for convert(::Type{Some{Any}}, ::Some{Any}), false, true, false)
julia> @btime convert(Some{Any}, $c)
1.001 μs (1 allocation: 16 bytes)
Some("foo")
julia> length(methods(Base.getproperty))
49
julia> length(methods(Base.convert))
240 Profiling reveals it's using dynamic dispatch after loading CSV, and wasn't before. I'm not sure if there's a general fix, it may just require #31536. |
Keep in mind My first thought was that this could be due to CategoricalArrays adding another method for |
There looks to be some type-piracy introduced by CategoricalArrays:
|
Jinx! |
Noted in JuliaDebug/JuliaInterpreter.jl#206 (comment)
The text was updated successfully, but these errors were encountered: