# Makie - High GPU usage for plots with a lot of points

**URL:** https://discourse.julialang.org/t/makie-high-gpu-usage-for-plots-with-a-lot-of-points/55199
**Category:** Visualization
**Tags:** makie
**Created:** [February 13, 2021, 10:19am UTC](https://discourse.julialang.org/t/makie-high-gpu-usage-for-plots-with-a-lot-of-points/55199 "2021-02-13T10:19:14Z")
**Posts on this page:** 16
**Page:** 1

<div class="post-metadata">

### Author: ![tt1234567](https://avatars.discourse-cdn.com/v4/letter/t/dec6dc/32.png) [@tt1234567](https://discourse.julialang.org/u/tt1234567)
#### Post date: [February 13, 2021, 10:19am UTC](https://discourse.julialang.org/t/makie-high-gpu-usage-for-plots-with-a-lot-of-points/55199/1 "2021-02-13T10:19:15Z")

</div>

My laptop struggles a bit when I plot large numbers of points with Makie. It’s not just while it’s plotting but it carries on using the GPU after the plot’s completed. I’m using Windows 10 on a laptop with a core i7 processor and Intel UHD graphics. There’s also an NVidia GeForce GTX 16 but I don’t think that gets used in this case.

For example, if I plot:

```julia
fig = Makie.Figure()
ax1 = fig[1,1] = Axis(fig)
ax2 = fig[2,1] = Axis(fig)
hm = heatmap!(ax1,rand(8000,257))

```

Then GPU usage is around 30%, according to Windows Task Manager, until the plot is closed. If I now add

```julia
pl = lines!(ax2,rand(2048000))

```

then GPU usage goes up to around 100% and doesn’t go down until the window’s closed. I realise that’s a lot of points, and I eventually I’ll get round to reducing the number, but is it expected behaviour that the GPU carries on being used even if the plot isn’t being updated? Curiously, in my actual application the plots get updated once a second and the GPU usage is actually less, at about 50%.

---

<div class="post-metadata">

### Author: ![sdanisch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sdanisch/32/1406_2.png) [@sdanisch](https://discourse.julialang.org/u/sdanisch)
#### Post date: [February 13, 2021, 11:07am UTC](https://discourse.julialang.org/t/makie-high-gpu-usage-for-plots-with-a-lot-of-points/55199/2 "2021-02-13T11:07:52Z")

</div>

Rendering happens in a renderloop, so it renders the plot ~30 times a second even if nothing happens.  
You can try to play around with this function to change the behavior of the loop: [GLMakie.jl/rendering.jl at 9fc8bd1b26c919aed155654424a473f1c973752a · JuliaPlots/GLMakie.jl · GitHub](https://github.com/JuliaPlots/GLMakie.jl/blob/9fc8bd1b26c919aed155654424a473f1c973752a/src/rendering.jl#L83)

---

<div class="post-metadata">

### Author: ![tt1234567](https://avatars.discourse-cdn.com/v4/letter/t/dec6dc/32.png) [@tt1234567](https://discourse.julialang.org/u/tt1234567)
#### Post date: [February 13, 2021, 11:59am UTC](https://discourse.julialang.org/t/makie-high-gpu-usage-for-plots-with-a-lot-of-points/55199/3 "2021-02-13T11:59:25Z")

</div>

Thanks for the reply, that explains what I’m seeing. Julia’s been great for prototyping my application and I’d like to stay with it and not have to move to C++ if possible. Hopefully with fewer points the GPU usage will be bearable.

---

<div class="post-metadata">

### Author: ![tt1234567](https://avatars.discourse-cdn.com/v4/letter/t/dec6dc/32.png) [@tt1234567](https://discourse.julialang.org/u/tt1234567)
#### Post date: [February 13, 2021, 1:15pm UTC](https://discourse.julialang.org/t/makie-high-gpu-usage-for-plots-with-a-lot-of-points/55199/4 "2021-02-13T13:15:05Z")

</div>

And using

```julia
set_window_config!(framerate=3.0)

```

brings the GPU usage right down and the plot update is still impressively fast. It took me a while to find the function as I was using Makie instead of GLMakie directly, but it’s solved my problem. Thanks again - it’s a great package and the system of observables has made it easy to produce a real-time display.

---

<div class="post-metadata">

### Author: ![sunbubble](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sunbubble/32/22022_2.png) [@sunbubble](https://discourse.julialang.org/u/sunbubble)
#### Post date: [February 16, 2021, 1:55pm UTC](https://discourse.julialang.org/t/makie-high-gpu-usage-for-plots-with-a-lot-of-points/55199/5 "2021-02-16T13:55:56Z")

</div>

Is it practical, or would it make sense to have an adaptive framerate system for makie by default? As in, bump the framerate if there’s interaction or some animation. The reason is that most of the time, there’s nothing moving on most plots, so we could save energy/resources when not needed.

**edit:** the user would then be able to set the maximum framerate or something along those lines.

---

<div class="post-metadata">

### Author: ![LaurentPlagne](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/laurentplagne/32/10103_2.png) [@LaurentPlagne](https://discourse.julialang.org/u/LaurentPlagne)
#### Post date: [February 16, 2021, 2:10pm UTC](https://discourse.julialang.org/t/makie-high-gpu-usage-for-plots-with-a-lot-of-points/55199/6 "2021-02-16T14:10:13Z")

</div>

I guess that you could handle this by controlling your observable updates.

---

<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: [February 16, 2021, 4:36pm UTC](https://discourse.julialang.org/t/makie-high-gpu-usage-for-plots-with-a-lot-of-points/55199/7 "2021-02-16T16:36:13Z")

</div>

We thought about this before, the requirement would be to intercept all observable signals that cause visual changes, and hook that up to the refresh event somehow. The implementation could potentially get really messy with our current attribute system, where every attribute has its own observable. We are already not so great at disconnecting stale connections to free up resources, this would add to that problem for now

---

<div class="post-metadata">

### Author: ![sunbubble](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sunbubble/32/22022_2.png) [@sunbubble](https://discourse.julialang.org/u/sunbubble)
#### Post date: [February 16, 2021, 7:30pm UTC](https://discourse.julialang.org/t/makie-high-gpu-usage-for-plots-with-a-lot-of-points/55199/8 "2021-02-16T19:30:25Z")

</div>

> [@jules](#):
>
> We thought about this before, the requirement would be to intercept all observable signals that cause visual changes, and hook that up to the refresh event somehow.

Just to play devil’s advocate for a little. Would it be okay to intercept all observable signals, without trying to figure out whether they change the visualisation? I wonder whether the complexity lies in the identification of whether drawing on a given signal would cause a (pardon the pun) observable change. It may be reasonable enough that if you’re interacting with a plot or adding values in a non visible region, even if there’s nothing changing, that you redraw.

---

<div class="post-metadata">

### Author: ![tt1234567](https://avatars.discourse-cdn.com/v4/letter/t/dec6dc/32.png) [@tt1234567](https://discourse.julialang.org/u/tt1234567)
#### Post date: [May 23, 2021, 11:26am UTC](https://discourse.julialang.org/t/makie-high-gpu-usage-for-plots-with-a-lot-of-points/55199/9 "2021-05-23T11:26:51Z")

</div>

Hi @sdanisch. I think this problem has got a lot worse, for me at least, with the latest release. I tried

```julia
using GLMakie
set_window_config!(framerate=framerate)
heatmap(rand(8000,257))

```

with different values of framerate using two versions of GLMakie and noted the GPU usage. The results were (approximately)

```julia
# GLMakie 0.2.9
# framerate=2, GPU 1%
# framerate=10, GPU 5%
# framerate=30, GPU 8%

# GLMakie 0.3.2
# framerate=2, GPU 45-100% (very variable)
# framerate=10, GPU 83-100%
# framerate=30, GPU 47-100%
# framerate=0.1, GPU 1-100% (window doesn't respond, unsurprisingly)

```

With the new version the GPU usage varies a lot where it was fairly steady with the old version. I’ve had to reduce the framerate to 2 on my real application (it was fine at 10) which is just about OK but makes it a bit unresponsive. I’m using Windows 10 and a UHD display with Intel UHD graphics 630 and NVidia GTX 1650 on a Dell XPS15.

---

<div class="post-metadata">

### Author: ![sdanisch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sdanisch/32/1406_2.png) [@sdanisch](https://discourse.julialang.org/u/sdanisch)
#### Post date: [May 23, 2021, 11:35am UTC](https://discourse.julialang.org/t/makie-high-gpu-usage-for-plots-with-a-lot-of-points/55199/10 "2021-05-23T11:35:28Z")

</div>

hm, maybe that’s regression since we now render that heatmap as a 8000x257 quad mesh 😓  
That’s 4,112,000 triangles, so quite a bit to chew for a GPU.  
We should try to bring back the fast path to render a regular heatmap as a single quad - meanwhile, you can try using `image` instead, which should still render everything as a single quad.  
Just confirmed: image stays at 1% gpu usage, while heatmap for the same array is at 100% for me.

---

<div class="post-metadata">

### Author: ![tt1234567](https://avatars.discourse-cdn.com/v4/letter/t/dec6dc/32.png) [@tt1234567](https://discourse.julialang.org/u/tt1234567)
#### Post date: [May 23, 2021, 11:45am UTC](https://discourse.julialang.org/t/makie-high-gpu-usage-for-plots-with-a-lot-of-points/55199/11 "2021-05-23T11:45:29Z")

</div>

Thanks, I’ll try that.

---

<div class="post-metadata">

### Author: ![tt1234567](https://avatars.discourse-cdn.com/v4/letter/t/dec6dc/32.png) [@tt1234567](https://discourse.julialang.org/u/tt1234567)
#### Post date: [May 23, 2021, 1:04pm UTC](https://discourse.julialang.org/t/makie-high-gpu-usage-for-plots-with-a-lot-of-points/55199/12 "2021-05-23T13:04:55Z")

</div>

That works fine. I confess I’m not sure what the difference between a `heatmap` and an `image` is anyway. In fact, the merged `DataInspector()` seems to work better with `image` as it gives x,y co-ordinates instead of indices into the data array.

---

<div class="post-metadata">

### Author: ![ffreyer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ffreyer/32/21569_2.png) [@ffreyer](https://discourse.julialang.org/u/ffreyer)
#### Post date: [May 23, 2021, 3:56pm UTC](https://discourse.julialang.org/t/makie-high-gpu-usage-for-plots-with-a-lot-of-points/55199/13 "2021-05-23T15:56:23Z")

</div>

Iirc the point of the heatmap/image differentiation was to simplify compatibility with other backends (like GR, not something as manual as Cairo or OpenGL).

DataInspector treats both the same, it goes off of `interpolation`. My thought was that with ínterpolation you probably want an exact position + color, and without you probably want something discrete relevant to the cell your hover. Maybe getting the (discrete) position would be better here? Maybe both, e.g. `($x, $y, H[$i, $j] = $z)`?

---

<div class="post-metadata">

### Author: ![tt1234567](https://avatars.discourse-cdn.com/v4/letter/t/dec6dc/32.png) [@tt1234567](https://discourse.julialang.org/u/tt1234567)
#### Post date: [May 23, 2021, 4:42pm UTC](https://discourse.julialang.org/t/makie-high-gpu-usage-for-plots-with-a-lot-of-points/55199/14 "2021-05-23T16:42:13Z")

</div>

I see. I hadn’t noticed that `interpolation` is on by default for `image`. For my purposes I’d prefer discrete position with `interpolation` off but in other cases indices might be better, so having both would be good. Is it possible to have more significant figures in the position? I’m only getting 4 sf and when I zoom in on a high resolution picture I could do with more.

Having `DataInspector` available has made Makie much more convenient for me - thanks!

---

<div class="post-metadata">

### Author: ![ffreyer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ffreyer/32/21569_2.png) [@ffreyer](https://discourse.julialang.org/u/ffreyer)
#### Post date: [May 23, 2021, 4:54pm UTC](https://discourse.julialang.org/t/makie-high-gpu-usage-for-plots-with-a-lot-of-points/55199/15 "2021-05-23T16:54:57Z")

</div>

No those are currently hard-coded. You could replace the method that generates the displayed string though:

```julia
function Makie.color2text(name, x::Float64, y::Float64, color)
    idxs = @sprintf("%0.6f, %0.6f", x, y)
    "$name[$idxs] = $(Makie.color2text(c))"
end

```

---

<div class="post-metadata">

### Author: ![tt1234567](https://avatars.discourse-cdn.com/v4/letter/t/dec6dc/32.png) [@tt1234567](https://discourse.julialang.org/u/tt1234567)
#### Post date: [May 23, 2021, 6:59pm UTC](https://discourse.julialang.org/t/makie-high-gpu-usage-for-plots-with-a-lot-of-points/55199/16 "2021-05-23T18:59:29Z")

</div>

I had to change the function arguments to `Makie.color2text(name, x::Float32, y::Float32, c)` but it works. Thanks, that’s amazing!
