# Is it possible to tune garbage collection for interactivity?

**URL:** https://discourse.julialang.org/t/is-it-possible-to-tune-garbage-collection-for-interactivity/99841
**Category:** Performance
**Created:** [June 4, 2023, 10:30am UTC](https://discourse.julialang.org/t/is-it-possible-to-tune-garbage-collection-for-interactivity/99841 "2023-06-04T10:30:55Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)
#### Post date: [June 4, 2023, 10:30am UTC](https://discourse.julialang.org/t/is-it-possible-to-tune-garbage-collection-for-interactivity/99841/1 "2023-06-04T10:30:55Z")

</div>

200-300 ms intervals of gc are very disruptive when interacting with plots in GLMakie, for example. It would be much better if GC ran more often but only for 5ms or so at a time so that the chance of dropping frames is lower. I have no idea if something like that would be feasible, but I see these kinds of delays as a big blocker for all kinds of uses that Julia could in principle have, where real time interaction is needed and longer pauses do not lead to “failures” (as in hard real time scenarios like controlling a plane or so), but are just very annoying and deteriorate the user experience a lot.

---

<div class="post-metadata">

### Author: ![oxinabox](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oxinabox/32/206603_2.png) [@oxinabox](https://discourse.julialang.org/u/oxinabox)
#### Post date: [June 4, 2023, 12:30pm UTC](https://discourse.julialang.org/t/is-it-possible-to-tune-garbage-collection-for-interactivity/99841/2 "2023-06-04T12:30:46Z")

</div>

It might be reasonable to insert soje manual `GC.gc()` calls into interactive use, so they happen at times that are good.

I Wonder if there is a way to say “maybe do GC here if you feel like it”

---

<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: [June 4, 2023, 12:44pm UTC](https://discourse.julialang.org/t/is-it-possible-to-tune-garbage-collection-for-interactivity/99841/3 "2023-06-04T12:44:28Z")

</div>

@jules, do you have an MWE so we can add it to list of things that the GC could do better at?

---

<div class="post-metadata">

### Author: ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)
#### Post date: [June 4, 2023, 6:04pm UTC](https://discourse.julialang.org/t/is-it-possible-to-tune-garbage-collection-for-interactivity/99841/4 "2023-06-04T18:04:17Z")

</div>

Not really special ones, like when you interact with an Axis in GLMakie, it has to compute new ticks etc and that all necessarily allocates. So you get a lot of these jerks when using the package because you’re usually dropping multiple frames when gc runs.

---

<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: [June 4, 2023, 6:53pm UTC](https://discourse.julialang.org/t/is-it-possible-to-tune-garbage-collection-for-interactivity/99841/5 "2023-06-04T18:53:40Z")

</div>

Right, but can you reproduce that with a simpleish script or does one need a full application/interactivity.

---

<div class="post-metadata">

### Author: ![oxinabox](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oxinabox/32/206603_2.png) [@oxinabox](https://discourse.julialang.org/u/oxinabox)
#### Post date: [June 6, 2023, 1:33pm UTC](https://discourse.julialang.org/t/is-it-possible-to-tune-garbage-collection-for-interactivity/99841/6 "2023-06-06T13:33:11Z")

</div>

I wonder if we did something like `GC.gc()` on the `MouseDown` event.  
So that you can hold and drag sliders, and it might have a little jitter at the start but when scrolling back and forth would be smooth.  
Maybe with a check to `Dates.Libc.TimeVal()` to prevent it from gc’ing too often. So repeated clicking also doesn’t stutter  
(`Test.LibC.TimeVal` runs in under 20ns where as `Dates.now()` takes 100 cos it constructs julia times structs)

---

<div class="post-metadata">

### Author: ![nsajko](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nsajko/32/221187_2.png) [@nsajko](https://discourse.julialang.org/u/nsajko)
#### Post date: [June 6, 2023, 2:41pm UTC](https://discourse.julialang.org/t/is-it-possible-to-tune-garbage-collection-for-interactivity/99841/7 "2023-06-06T14:41:47Z")

</div>

> [@oxinabox](#):
>
> a way to say “maybe do GC here if you feel like it”

Maybe `GC.safepoint()`, or `GC.gc(false)`?
