Closed charleskawczynski closed 1 month ago
Profiling this shows that we spend all the time in may_contain_union_decision
. I wonder if because nest_val
makes so many types a query here gets more expensive?
We spend it in.https://github.com/JuliaLang/julia/blob/53d3ca9855db0308ddf2044a3a0f21f3de492cf3/src/subtype.c#L1530
I don't know if it's helpful, but maybe it's useful to print both timings:
Base.@kwdef struct Nested{A,B}
num::Int = 1
end
nest_val(na, nb, ::Val{1}) = Nested{na, nb}()
nest_val(na, nb, ::Val{n}) where {n} = nest_val(Nested{na, nb}, Nested{na, nb}, Val(n-1))
nest_val(na, nb, n::Int) = nest_val(na, nb, Val(n))
nest_val(n) = nest_val(1, 1, n)
foo(t::Nested) = 1
for i in 1:4:25
let i=i
local NV
ts = @elapsed begin
NV = nest_val(i)
end
tc = @elapsed begin
foo(NV)
end
println("make struct, compile foo ($ts, $tc)")
end
end
Which gives:
make struct, compile foo (1.13e-5, 1.1e-6)
make struct, compile foo (0.0145189, 6.02e-5)
make struct, compile foo (0.0176925, 0.0001021)
make struct, compile foo (0.0184645, 6.44e-5)
make struct, compile foo (0.0189012, 7.05e-5)
make struct, compile foo (0.012758, 8.29e-5)
make struct, compile foo (0.0191793, 7.33e-5)
make struct, compile foo (1.39e-5, 1.2e-6)
make struct, compile foo (0.0151348, 9.43e-5)
make struct, compile foo (0.0153842, 9.62e-5)
make struct, compile foo (0.0110747, 0.0001918)
make struct, compile foo (0.0246075, 0.0018085)
make struct, compile foo (0.1408822, 0.0237191)
make struct, compile foo (1.9444539, 0.3840136)
make struct, compile foo (6.9e-6, 1.3e-6)
make struct, compile foo (0.0257007, 7.14e-5)
make struct, compile foo (0.0356919, 6.56e-5)
make struct, compile foo (0.0343293, 0.0001467)
make struct, compile foo (0.0535389, 0.0014321)
make struct, compile foo (0.3459823, 0.0193436)
make struct, compile foo (5.0870128, 0.3232764)
make struct, compile foo (7.1e-6, 2.4e-6)
make struct, compile foo (0.02574, 4.6e-5)
make struct, compile foo (0.0330718, 4.37e-5)
make struct, compile foo (0.0341266, 0.0001204)
make struct, compile foo (0.0559988, 0.0014925)
make struct, compile foo (0.3904373, 0.0213976)
make struct, compile foo (5.7038262, 0.3391496)
FWIW, the regression still exists but is not nearly as severe when Nested
is a singleton (Base.@kwdef struct Nested{A,B} end
). (Suggested by @dennisYatunin)
I'm also seeing different impacts on windows vs macos, but the regression is on both.
I know the SciML ecosystem has some pretty heavily typed code, so @ChrisRackauckas may also be interested in this issue.
I really think we need to split the ideas of "please specialize" and "allow dispatching"
@ChrisRackauckas that's #11339
@topolarity or @vtjnash can one of you look into this?
I think I found a regression with compiling methods with increasing type information (cc @gbaraldi). Here is a reproducer:
Julia 1.8 🚀
Julia 1.9 🐢
Julia 1.10 🐢
Julia 1.11.0-rc3 🐢