I’m using DifferentialEquations.solve() to solve an ODE. It involves a lot of numerical parameters and functions. I get the solution correctly using the DifferentialEquations.VCABM3() method (Adams-Bashford-Moulton). However, it takes a long time to solve the ODE at the first attempt, being fast after that if I repeat the computation.

Here are the times that I got:

10.455641 seconds (10.55 M allocations: 547.724 MiB, 6.30% gc time)
0.006234 seconds (58.86 k allocations: 1.002 MiB)
0.007289 seconds (58.86 k allocations: 1.002 MiB)
0.006561 seconds (58.86 k allocations: 1.002 MiB)
0.006577 seconds (58.86 k allocations: 1.002 MiB)
0.005462 seconds (58.86 k allocations: 1.002 MiB)

The first time corresponds to the first attempt, and the following are shown after that.

Why might this be happening? Is there any way to get faster times from the first attempt?

The times that I’ve attached come from the compilation of the solver only. Before that, I ran the packages, parameters and functions needed separately.

There is a compilation which happens with each new ODE derivative function. We have a prototype way to get rid of that in the near future for the standard Float64 case: