# Tracking allocations lost its way?

**URL:** <https://discourse.julialang.org/t/tracking-allocations-lost-its-way/96280>\
**Category:** General Usage\
**Tags:** memory-allocation\
**Created:** [March 18, 2023, 5:59pm UTC](https://discourse.julialang.org/t/tracking-allocations-lost-its-way/96280 "2023-03-18T17:59:30Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [March 18, 2023, 5:59pm UTC](https://discourse.julialang.org/t/tracking-allocations-lost-its-way/96280/1 "2023-03-18T17:59:30Z")

</div>

I get a `@time` report:

`92.505464 seconds (20.12 M allocations: 2.683 GiB, 0.29% gc time) `.

When I look at the code with `--track-allocations=all`, the following (abbreviated) file is obtained.  
All lines with any allocation whatsoever are included here. Clearly the number of allocations is  
about 10, not 20 million. What is it talking about in the `@time` report?

```julia

        - function cs!(outputI, outputJ, outputV, I, J, V, Nc)
 40240112 count = fill(zero(eltype(J)), Nc+1)
        0 @inbounds for i in eachindex(J)
...
        0 end
        0 return nothing
        - end
        - 
        - function cp(Nc, J)
 40240112 colptr = fill(0, Nc+1)
        - p = 1
...
        0 return colptr
        - end
        - 
        - function cr(N, colptr, I, V)
        0 maxrows = maximum(diff(colptr))
        - # newrows = fill(zero(eltype(I)), maxrows)
        - # newvals = fill(zero(eltype(V)), maxrows)
      336 prma = fill(zero(eltype(I)), maxrows)
458768240 newI = similar(I)
458768240 newV = similar(V)
 40240112 newcolptr = similar(colptr)
        0 newcolptr[1] = colptr[1]
...
        0 end
458768048 newI = newI[1:p-1]
458768048 newV = newV[1:p-1]
        0 return newcolptr, newI, newV
        - end
        - 
        - function sc(inputI, inputJ, inputV, Nr, Nc)
458768240 I = similar(inputI)
458768240 J = similar(inputJ)
458768240 V = similar(inputV)
        - 
...
        - end
        - 

```

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [March 18, 2023, 6:49pm UTC](https://discourse.julialang.org/t/tracking-allocations-lost-its-way/96280/2 "2023-03-18T18:49:38Z")

</div>

Could maybe be allocations in Base? [Hunting down allocations with Julia 1.8's Allocation Profiler | Nathan Daly, Pete Vilter - YouTube](https://www.youtube.com/watch?v=BFvpwC8hEWQ) is a better way to find allocations imo.

---

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [March 18, 2023, 8:58pm UTC](https://discourse.julialang.org/t/tracking-allocations-lost-its-way/96280/3 "2023-03-18T20:58:13Z")

</div>

Thanks for the pointer!

Wouldn’t it actually be nice to have the allocations in the base also in the code listing?  
That is useful information…

---

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [March 18, 2023, 9:36pm UTC](https://discourse.julialang.org/t/tracking-allocations-lost-its-way/96280/4 "2023-03-18T21:36:42Z")

</div>

You were right apparently: `sortperm!` allocates 16 bytes. Edit: Which could be eliminated. Now the code is down to 26 allocations from 20M.

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [March 18, 2023, 10:07pm UTC](https://discourse.julialang.org/t/tracking-allocations-lost-its-way/96280/5 "2023-03-18T22:07:51Z")

</div>

> [@PetrKryslUCSD](#):
>
> `--track-allocations=all`

my understanding is this thing is soft deprecated, forgot reason

---

<div class="post-metadata">

**Author:** ![gbaraldi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gbaraldi/32/22101_2.png) [@gbaraldi](https://discourse.julialang.org/u/gbaraldi)\
**Post date:** [March 19, 2023, 1:43am UTC](https://discourse.julialang.org/t/tracking-allocations-lost-its-way/96280/6 "2023-03-19T01:43:53Z")

</div>

Because of the new allocation profiler. This one was unreliable due to changing how code is emitted, possibly leading to false positives.
