AlgebraOfGraphics.jl
AlgebraOfGraphics.jl copied to clipboard
How to improve polygon rendering performance?
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:
MeshVizwhich is (like AoG) based on MakieGadflyPlots
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?