Hi!
I’m trying to understand why is the using the Plots.jl @animate macro slower than plotting and saving many times. I destilled my real case into this hopefully MWE.
I have a function that creates a plot with several heatmaps and a function that creates an animation by changing the timestep to be plotted.
Using currently julia 1.5 RC 1
julia> using Plots, BenchmarkTools; gr();default(fmt=:png)
julia> function letsplot(array,indt)
p1 = @views heatmap(array[:,:,indt])
p2 = @views heatmap(array[:,:,indt])
p3 = @views heatmap(array[:,:,indt])
p4 = @views heatmap(array[:,:,indt])
p5 = @views heatmap(array[:,:,indt])
p6 = @views heatmap(array[:,:,indt])
plot(p1,p2,p3,p4,p5,p6)
end
julia> function animate_test(array)
anim = @animate for indt in 1 #Only one timestep
letsplot(array,indt)
end
end
If I just call the plotting function I get a plot very rapidly.:
julia> @btime letsplot($rand(500,500,100),1)
97.810 ms (34932 allocations: 215.63 MiB)
But when wrapping it in an animation, the allocations skyrocket, even if I am only iterating in one number.
julia> @btime animate_test($rand(500,500,100))
12.632 s (240254552 allocations: 4.57 GiB)
In the real case scenario I am doing 600 timesteps and it takes around 40 minutes in creating the final animation. In this example only going through 1 timestep inside the @animate macro creates a lot of allocations and increases the execution time (by a lot 100 miliseconds vs 12 seconds).
Is there a way to make this process more efficient? I’m thinking that in the real case most of the time is spent in garbage collection.