-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
surface() with CairoMakie backend, lots of allocations? #266
Comments
This could potentially be sped up by adding some precompile statements, I'll give that a look. The allocations when using CairoMakie are expected, because it internally translates the surface grid to a triangle mesh, which has |
Edit: it turns out that I mixed up lons and lats when making this example work without the JLD file (which I didn't see in the issue), but that did expose an interesting bug in CairoMakie so I'll call it fair :D |
Here's a more minimal MWE, and the timings broadly agree with what you show: using GeoMakie
using CairoMakie
#using GLMakie
function go()
lons = LinRange(-180, 180, 390)
lats = LinRange(-90, 90, 390)
values = rand(length(lons), length(lats))
t0 = time()
println("Figure()")
@time fig = Figure()
println("GeoAxis()")
@time ax = GeoAxis(fig[1,1],
source="+proj=longlat +datum=WGS84",
dest="+proj=lcc +lon_0=5 +lat_1=50 +lat_2=55")
println("surface!()")
@time surf = surface!(ax, lons, lats, values; shading=NoShading)
println("Colorbar()")
@time Colorbar(fig[2,1], surf; ticklabelsize=10, tickwidth=1, vertical=false)
println("display()")
@time display(fig)
t1 = time()
println("time-to-plot $((t1-t0)*1000)ms")
end
go() |
Using TimerOutputs (manually inserted into Makie) gets me the result below, which clearly indicates that defining and drawing the mesh to Cairo takes the bulk of time here. We could get this down a bit maybe by implementing a mesh renderer in CairoMakie but that would take a while.
|
Why draw as a triangle mesh, and not quads? That would potentially half the number of draw calls (and I'm sure Cairo can support it) |
Quads are not well supported supported by vector graphics (Cairo usually rasterizes them in many formats, and the file sizes get pretty insane even if not rasterized), and the majority of time is spent preparing the Cairo pattern anyway. I had tried this before but the tradeoff simply isn't worth it - the better option is to implement a pure Julia mesh rasterizer (not actually too hard) and then rasterize the mesh to an image, and emit the image. |
I don't know all the details of what frequently gets output from Cairo when used from Julia (I only use it to rasterize vector graphics directly from C/C++, not to save to svg for example), but to which formats does it rasterize?
Is that in https://github.com/MakieOrg/Makie.jl/blob/77f2cfdb15b85374f449c5cdc3ad3c108cf858e2/CairoMakie/src/primitives.jl#L975? Can't you create the pattern once and then reuse it for all triangles? |
Usually SVG (quads not supported, so the whole SVG gets rasterized internally), PDF (quads supported but filesize >100mb vs 20mb with triangles), or PNG (long rasterization time).
Not to my knowledge, unless Cairo has a nice API for that? We are changing the points and the colors at each pattern, so it's a nontrivial reconstruction. |
cf MakieOrg/Makie.jl#4112 - this may be the reason why this issue exists. |
First run from REPL (10.5s to plot):
Second run, same REPL session (1.95s):
Even in the second run the
display()
call seems to have lots of allocations for such a small dataset. Is this to be expected, and particular to GeoMakie?The text was updated successfully, but these errors were encountered: