Using TimerOutputs, registers allocs, where @allocated does not?

Hello!

I have a bit of a complex code, where I use TimerOutputs to track progress. I have the following code bit:

In Line 343 I am updating the position variable. Position, Velocity, Acceleration are SVectors inside of Vectors and the other variables are floating point values. TimerOutputs gives the following:

image

If I comment line 343 out:

image

Next I try to check if allocations occur using @allocated as such:


image

No print statements appear in terminal, i.e. @allocated returns zero, but the SimulationLoop still returns average of 985 bytes.

I am a bit perplexed how this can happen, and I wonder if anyone has experienced something similar?

I have done a small check and noted that:


image

Where it is seen that adding SVector(0,0) to Position does not allocate, but adding 1,1 does.

I don’t really have a MWE sorry, since this is quite nested code in a branch of a repo I am working on, but sharing here since some can probably provide me some guidance on whether what I am seeing is actual or if it is a bug in TimerOutputs.

Kind regards

After debugging for a while I found it. By using TimerOutputs at each function call instead of the total function:

image

I found 989 bytes. It is a weird number and it comes from:

function UpdateNeighbors!(args...)
    ExtractCells!(Cells,Position,CutOff)

    sortperm!(SortedIndices,Cells) #The first call to sortperm! compiles a new method when working with CartesianIndex{Dimensions} apparently
    # first iteration @time: -> 0.000139 seconds (2 allocations: 23.734 KiB)

So yeah, tracking allocations is rewarding and frustrating haha

For future reference, solution here: