You are of course right. That sleep call was just for illustration, I don’t plan to include that in my final code.
I timed updating the frame with:
using WGLMakie, JSServe
n = 200 # frame dimensions
img = Node(rand(UInt8, n, n))
function f()
img[] = rand(UInt8, n, n)
end
App() do session::Session
image(img)
end
using BenchmarkTools
@btime f();
and got:
# n = 100 -> 4.893 ms (10690 allocations: 586.30 KiB)
# n = 200 -> 20.830 ms (40695 allocations: 2.07 MiB)
# n = 400 -> 87.734 ms (160697 allocations: 8.10 MiB)
# n = 800 -> 353.295 ms (640699 allocations: 28.87 MiB)
I also found out that the timings do not improve even if I use a function like this one:
function f(img, n)
for i in eachindex(img[])
img[][i] = rand(UInt8)
end
img[] = img[]
end
Which reduces allocations. So most of the time is spent on data transfer? @sdanisch is this performance (about 200 x 200 pixels at 30 fps) right? Or am I missing something?