Skip to content
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

How to improve polygon rendering performance? #311

Closed
roland-KA opened this issue Dec 15, 2021 · 2 comments
Closed

How to improve polygon rendering performance? #311

roland-KA opened this issue Dec 15, 2021 · 2 comments

Comments

@roland-KA
Copy link

I've made a Pluto notebook which reads the shapes of all countries (using Shapefile) from Natural Earth and renders them, thus creating a world map.

I've used AoG for this purpose but implemented the same script also using the following packages:

  • MeshViz which is (like AoG) based on Makie
  • Gadfly
  • Plots
Code using AoG
using AlgebraOfGraphics, GLMakie
using Shapefile, ZipFile
using Downloads: download

zipfile = download("https://www.naturalearthdata.com/http//www.naturalearthdata.com/download/110m/cultural/ne_110m_admin_0_countries.zip")

r = ZipFile.Reader(zipfile);
for f in r.files
    println("Filename: $(f.name)")
    open(f.name, "w") do io
    	write(io, read(f))
    end
end
close(r)

countries = Shapefile.Table("./ne_110m_admin_0_countries.shp")
plt = geodata(countries) * mapping(:geometry, color = :NAME_ID) * visual(Poly)
fg = draw(plt, legend=(position=:top,); axis=(width = 1400, height = 900))
Versioninfo:
Julia Version 1.6.1
Commit 6aaedecc44 (2021-04-23 05:59 UTC)
Platform Info:
  OS: macOS (x86_64-apple-darwin18.7.0)
  CPU: Apple M1
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-11.0.1 (ORCJIT, westmere)

Surprisingly, the different implementations showed vastly differing run time performances for drawing the map (consisting of 290 polygons). As in almost all Julia programs the first execution is much slower than on follow up runs, I measured execution times for the first as well as for the next run of each script and got the following numbers (all times are in seconds):

Implementation 1st run 2nd run
AoG + GLMakie 96 50
AoG + CairoMakie 95 50
MeshViz + GLMakie 55 2.5
MeshViz + CairoMakie 54 3
Plots 2 0.1
Gadfly 1 < 0.001

As can bee seen all Makie-based implementations are generally slower (why?). But there is also a noticeable difference between AoG and MeshViz, despite being based on Makie in both cases. Especially on the 2nd run AoG lacks the speedup which can be seen in MeshViz.

So I wonder if anything can be changed in my implementation using AoG to get a better performance?

@jkrumbiegel
Copy link
Member

I've looked into this just now and while the times are better on my machine, they're still bad. I did this:

@time begin
    plt = data(countries) * mapping(:geometry, color = :NAME_ID) * visual(Choropleth)
    fg = draw(plt, scales(Color = (; legend = false)), legend=(position=:top,))
    display(fg)
end

Note the Color = (; legend = false). Without that (so with the legend showing) I get 7.962373 seconds (53.77 M allocations: 2.181 GiB, 3.35% gc time, 0.00% compilation time). With it (so no legend) I get 0.194179 seconds (678.70 k allocations: 56.869 MiB, 18.62% gc time, 0.00% compilation time). So the slowness here is basically all legend. Of course, there are 177 legend entries, which is a lot, so the underlying slowness of Legend is compounded, probably quadratically.

I'll close this here as I'm pretty sure the issue is on Makie's side.

@roland-KA
Copy link
Author

Ok, thanks. Then we know at least where the problem is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants