Improving performance of solving ODESystem (Catalyst.jl)

Catalyst/ModelingToolkit build non-allocating functions. You can see this because your allocations won’t change if you turn saving off and increase the time span (i.e. longer solves don’t increase the allocations). Thus the memory cost is:

  1. Compiling new code
  2. Setting up a new solve call
  3. Saving values out

If you’re doing save_everystep = false you should be fine on (3). But are you avoiding code compilation each time? It’s only if prob !== nothing, which I haven’t looked at the code close enough to see but given you have a branch to protect against it you’re probably fine.

So then if you’ve done that correctly (and are measuring post compilation), the only other allocation is in the startup time of the solve call. You can move to the integrator interface (Integrator Interface · DifferentialEquations.jl) and just have a single integrator that reinit!s to avoid recreating the solver caches, and this would make it fully non-allocating.

But to know if that’s even required, you should try benchmarking first. Use GitHub - tkluck/StatProfilerHTML.jl: Show Julia profiling data in an explorable HTML page to create flamegraph: that will tell you what area of the code is taking all of the time.

(I’m still travelling so I haven’t gotten a chance to run it, but the flamegraph is the first thing I would make)