Performance regression with SAs as parameters in DiffEqs on Julia 1.6

Hi all,

I have some code where I pass parameters to ODE problems and it had some performance regressions with Julia 1.6.

I distilled the code to highlight what seems to me to be at the root of the problem - passing Static Arrays as parameters in my ODEs. I know the matrix sizes I use are borderline for SA vs Arrays but in my code the matrices are smaller but there are more of them. The 25x25 size is to exacerbate the problem without having to add many parameters. The main issue are the long compilation times, subsequent runs are faster.

I would be grateful if someone can point out how to speed up the code or a better way of implementing it (without just using Arrays instead of SAs – SAs are an easy wait to get my code running without allocations).

Timings in Julia 1.5

  8.261212 seconds (12.02 M allocations: 585.323 MiB, 5.57% gc time)
 13.653073 seconds (2.95 M allocations: 137.620 MiB, 0.42% gc time)

Timings in Julia 1.6

 17.030075 seconds (11.62 M allocations: 660.076 MiB, 2.80% gc time, 100.00% compilation time)
 81.326858 seconds (2.73 M allocations: 145.057 MiB, 0.09% gc time, 100.00% compilation time)


using OrdinaryDiffEq
using LinearAlgebra
using StaticArrays

function f!(ẋ,x,p,t)
  ẋ .= 0
tspan = (0.0, 100.0)
x₀ = zeros(25)

Q = SMatrix{15,15}(1.0e-1I)
p = Q,Q,Q

prob = ODEProblem(f!,x₀,tspan,p)

@time sol = solve(prob, Tsit5());

Q = SMatrix{25,25}(1.0e-1I)
p = Q,Q,Q

prob = ODEProblem(f!,x₀,tspan,p)

@time sol = solve(prob, Tsit5());
1 Like