SciML / StochasticDiffEq.jl

Solvers for stochastic differential equations which connect with the scientific machine learning (SciML) ecosystem
Other
245 stars 66 forks source link

Allocation in SROCK2 solver #478

Closed axsk closed 1 year ago

axsk commented 2 years ago

https://github.com/SciML/StochasticDiffEq.jl/blob/11f3a3c22e1ac73355ae3c76109e88fed6c89d91/src/perform_step/SROCK_perform_step.jl#L428

The line in question is allocating zeros In my case the allocation makes up for 6% of total solver time.

Not a huge thing but I thought I'd bring it up.

ChrisRackauckas commented 2 years ago

I don't see how that line is allocating zeros, it looks like it should just build a range (cheap) and then broadcast the whole line?

axsk commented 2 years ago

I would not have seen it without the VSCode @profview image

ChrisRackauckas commented 2 years ago

Oh it's allocating a bit array somewhere? That's wild. Yeah...

axsk commented 2 years ago

Thats the right allocation. To the left there is a call to

function (-)(B::BitArray)
    A = zeros(Int, size(B))
    ...
end

in bitarray.jl, L1149. Does this mean the broadcast is not working?

ChrisRackauckas commented 2 years ago

Try moving the range construction to another line and then doing @..