I’ve attached a screenshot of my flame profile. I’ve read that red bars near the top signal a problem with type instability. But I have specified the type of every struct member and the vast majority of my code relies on side effects, not return values.
Here’s one function that is causing multiple red bars, It gets called a lot, so it makes sense that it shows a wide bar in the flame profile. But I don’t know what’s causing the redness. Anyone have any insights?
function augmentCount!(base, cd, fvi, fv, fromTmp; w = 1, inc=1, numIndicesCutoff = 10_000) #w is width, inc is count to increment
cdtw = cd.taskDat
c = 0
if fromTmp
while length(cdtw.countsLow[w]) < fvi
push!(cdtw.countsLow[w], 0)
end
if cdtw.countsLow[w][fvi] + inc < typemax(UInt8)
c = cdtw.countsLow[w][fvi] += inc
elseif cdtw.countsLow[w][fvi] < typemax(UInt8)
cdtw.countsLow[w][fvi] = typemax(UInt8)
base.countsMed[w][fv] = inc + cdtw.countsLow[w][fvi]
c = base.countsMed[w][fv]
elseif haskey(base.countsMed[w], fv)
if base.countsMed[w][fv] + inc <= typemax(UInt16)
c = base.countsMed[w][fv] += inc
else
c = base.countsHi[w][fv] = inc + base.countsMed[w][fv]
delete!(base.countsMed[w], fv)
end
else c = base.countsHi[w][fv] += inc
end
else
if base.countsLow[w][fvi] + inc < typemax(UInt8)
c = base.countsLow[w][fvi] += inc
elseif base.countsLow[w][fvi] < typemax(UInt8)
base.countsLow[w][fvi] = typemax(UInt8)
c = base.countsMed[w][fvi] = d.countsLow[fvi] + inc
elseif haskey(base.countsMed[w], fvi)
if base.countsMed[w][fvi] + inc <= typemax(UInt16)
c = base.countsMed[w][fvi] += inc
else delete!(base.countsMed[w], fvi)
base.countsHi[w][fvi] += inc
end
else base.countsHi[w][fvi] += inc
end
end
return c
end
One sample call: c = augmentCount!(base, cd, fvi, fv, true; w=1)
Another: c2 = augmentCount!(base, cd, binFvi, binFv, fromTmp; w=2)
The types of the args are as follows: base is an immutable struct, cd is a mutable struct, fvi and binfvi are Ints, fv and binFV are small tuples, fromTmp is a Bool, and w is an Int. Would it help if I posted the contents of the structs?