# Understanding GC time

**URL:** <https://discourse.julialang.org/t/understanding-gc-time/127127>\
**Category:** Performance\
**Tags:** question\
**Created:** [March 19, 2025, 9:08am UTC](https://discourse.julialang.org/t/understanding-gc-time/127127 "2025-03-19T09:08:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![pjuergens](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pjuergens/32/28380_2.png) [@pjuergens](https://discourse.julialang.org/u/pjuergens)\
**Post date:** [March 19, 2025, 9:08am UTC](https://discourse.julialang.org/t/understanding-gc-time/127127/1 "2025-03-19T09:08:23Z")

</div>

Hello together,

I am wondering what determines the time that the garbage collector needs. I have a complex simulation where I was hunting down allocations, but surprisingly even though I could heavily reduce number and amount of allocations, GC time didn’t change significantly. Before optimization I had `997.37 k allocations: 98.777 MiB, 14.90% gc time`, after I could reduce it to `517.18 k allocations: 55.230 MiB, 20.16% gc time`, overall timing is in both cases in the order of 0.8s. I actually thought the gc time should scale with number or amount of allocations, but apparently it does not.

I am manually evoking GC.gc() at the end of the simulation due to [this issue](https://discourse.julialang.org/t/understanding-memory-usage-in-julia/101647/21). I have to test if this is still needed. So can it be that the advantage of reducing allocations only lies in that gc is needed less often while gc time itself is always the same?

---

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [March 19, 2025, 11:51am UTC](https://discourse.julialang.org/t/understanding-gc-time/127127/2 "2025-03-19T11:51:14Z")

</div>

> [@pjuergens](#):
>
> I am manually evoking GC.gc()

Don’t do that. Should not be needed any longer for recent versions of Julia.

And try to start Julia with

```julia
 julia --project --gcthreads=8,1

```

depending on the number of cores of your CPU.
