Too much garbage collection for a simple vector addition operation

ducanh-le
Thu, 27 Jul 2023 19:48:51 +0000
Performance

Hi everyone,

I’m trying to optimize my code. When look at the profiler, the 2nd and the 3rd line below got GC flags:

function resourceAvailable(v::Int32, a::Int32, usedResource::Vector{Int32}, md::ModelData)
    neededResource::Vector{Int32} = usedResource .+ md.r[md.ct[v]][a]
    return all(x -> x >= 0, md.cap .- neededResource), neededResource
end

This is my ModelData struct:

struct ModelData
        ct::Vector{Int32}
        cap::Vector{Int32}
        r::Vector{Vector{Vector{Int32}}}
end

I tried some things in the StaticArrays package but nothing help. Can someone please explain why? Here is the profiler result:

Thanks.

13 posts - 6 participants