Reduce GC time

fdekerme
Mon, 11 Sep 2023 10:03:43 +0000
Performance

Hello ,
I tried to optimize my code to reduce GC time. Among other things, I tried to implement “in place” operations, in particular with a long GC function “is_intersect!”, which checks whether a given interval intersects with an interval list . However, the following code structure doesn’t change anything to my GC time compared to a “naive” implementation where I create new variable at each step. Do you see an implementations error in the following code?

A structure I used :

using IntervalSets
Base.@kwdef struct S
    id::Int16
    number_of_interval::Int16
    intervals::Vector{ClosedInterval{Float64}}
    ...
end

The is_intersect! function :

function is_intersect!(interval_1::Interval, structure_1::S, is_intersect :: Vector{Bool})
    is_intersect[1] = false
    for interval in structure_1.intervals
        if !isempty(intersect(interval_1, interval))
            is_intersect[1] = true
        end
    end
end

The main function :

function main(structure_1)
    compartment_id = 0
    t = 0.0
    is_intersect = Vector{Bool}(undef, 1)
    time_in_compartment = Vector{Float64}(undef, 1)
    while t < duration
        time_in_compartment[1] = rand(1)[1]

        if compartment_id == 0
            is_intersect!(t .. (t + time_in_compartment[1]), structure_1, is_intersect)

      ...

thanks !
fdekerm

8 posts - 4 participants