-
Notifications
You must be signed in to change notification settings - Fork 152
Description
As described in JuliaLang/julia#49472, using StaticArrays.jl with Julia v1.9 and --check-bounds=no causes the SVector constructor to be type unstable even for the simplest invocations.
To reproduce, start Julia v1.9 (RC1 or later were tested and reproduce this problem) with --check-bounds=no and then run the following:
julia> using StaticArrays
julia> @code_warntype SVector(1)
MethodInstance for (SVector)(::Int64)
from (::Type{SA})(x...) where SA<:StaticArray @ StaticArrays ~/hackathon/perf/mwe-staticarrays/rc1/tmp-depot/packages/StaticArrays/4uslg/src/convert.jl:160
Static Parameters
SA = SVector
Arguments
#self#::Type{SVector}
x::Tuple{Int64}
Body::Any
1 ─ nothing
│ %2 = $(Expr(:static_parameter, 1))::Core.Const(SVector)
│ %3 = StaticArrays.Args(x)::StaticArrays.Args{Tuple{Int64}}
│ %4 = StaticArrays.construct_type(%2, %3)::Any
│ %5 = (%4)(x)::Any
└── return %5Without --check-bounds=no, we get the expected, type stable output:
julia> using StaticArrays
julia> @code_warntype SVector(1)
MethodInstance for (SVector)(::Int64)
from (::Type{SA})(x...) where SA<:StaticArray @ StaticArrays ~/hackathon/perf/mwe-staticarrays/rc1/tmp-depot/packages/StaticArrays/4uslg/src/convert.jl:160
Static Parameters
SA = SVector
Arguments
#self#::Type{SVector}
x::Tuple{Int64}
Body::SVector{1, Int64}
1 ─ nothing
│ %2 = $(Expr(:static_parameter, 1))::Core.Const(SVector)
│ %3 = StaticArrays.Args(x)::StaticArrays.Args{Tuple{Int64}}
│ %4 = StaticArrays.construct_type(%2, %3)::Core.Const(SVector{1, Int64})
│ %5 = (%4)(x)::SVector{1, Int64}
└── return %5This regression renders StaticArrays.jl virtually unusable with Julia v1.9 for many HPC workloads (hot kernels that make generous use of SVector basically grind to a halt). In the linked julia issue above it was hinted that this is not going to be fixed in Julia base, and @vchuravy suggested that I should rather file an issue here (keeping fingers crossed 🙏).
cc @ranocha