Closed
Description
As also described in JuliaArrays/StaticArrays.jl#1282, there is a large performance regression with v1.11
when using StaticArrays
:
using LinearAlgebra, StaticArrays, BenchmarkTools
function mwe1(a, X, n)
K = zeros(SMatrix{3,3})
for i in 1:n
k = a * i
K += k * X * X'
end
return K
end
@btime mwe1(1e-5, SVector{3}(1.0, 1.0, 1.0), 1_000_000);
❯ julia +1.10.5 --project -t 6 mwe.jl
1.070 ms (0 allocations: 0 bytes)
❯ julia +1.11.1 --project -t 6 mwe.jl
129.890 ms (7000000 allocations: 289.92 MiB)
Interestingly, the problem can be solved by changing k * X * X'
to k * (X * X')
:
function mwe3(a, X, n)
K = zeros(SMatrix{3,3})
for i in 1:n
k = a * i
K += k * (X * X')
end
return K
end
@btime mwe3(1e-5, SVector{3}(1.0, 1.0, 1.0), 1_000_000);
❯ julia +1.10.5 --project -t 6 mwe.jl
805.458 μs (0 allocations: 0 bytes)
❯ julia +1.11.1 --project -t 6 mwe.jl
708.208 μs (0 allocations: 0 bytes)