Performance tips for differential equation RHS

It’s difficult to keep track of what your current code looks like, but if you still have this part there

you should fix it. This allocates and copies an entire vector, just to read its length. That’s very wasteful. Instead, just use size which has virtually zero cost:

N = size(coupling_matrix, 2)

Something is seriously wrong there. Are you on Julia 1.10? It added some type instabilities.

1 Like

You’re right. Declaring the elements of coupling_matrix as floats and introducing loop vectorization just helped a ton. I don’t have access to the same PC as before, but it just sped up about 4x. Thank you!

1 Like