I am using Julia to solve set of differential equations of a omni-wheeled mobile robot. It took 1264.41 sec (21.07 min) to solve the system (But in mathematica, it took less than 4s). In the time, it showed 99% time is for the compilation. I would like to know is there a way that I can save the compiled file and reuse it/ any methods to speed up the solver. I am willing to use this model in a Reinforcement learning algorithm. Also, only the first four variables gave me the results matches with Mathematica or Python. Rest of the variables in Julia show as zero.
I am using an i7 11th generation processor with a 16GB RAM.

The code is lengthy to post here. I am sharing google dive link.

I think it is a huge beast and almost nobody can deal with this kind of code. You need to find a structure to it. For example, find an intermediate vector with as a function of parameters and ODE states and etc. Then define the derivatives as a matrix vector product. It can also be cascaded layers of these matrix vector multiplications. However, If you write explicitly as it is now almost no one can reason about it.

A huge beast is almost an understatement , the dynamics definition is over 45k lines of code… I assume that comes from some symbolic code generation? Perhaps you could perform this code generation differently, e.g., using common sub-expression elimination?

sol =@time solve(prob,BS3(),saveat=10/200000,abstol=1e-8,reltol=1e-8)

What’s the reason for using BS3? That’s a terrible choice for low tolerances, the docs highly highly recommend against doing this. And with such a small saveat, it’s better to just use the continuous interpolation.

sol =@time solve(prob,Vern9(),abstol=1e-8,reltol=1e-8)

is going to be a lot faster. But yes, the main issue here is that 45k lines of code will take awhile to compile. I’d recommend using a lower optimization level if you’re going to do this, or just don’t generate such a large code and keep loops rolled