Open oscarvdvelde opened 1 month ago
Huh, this could have multiple issues, but it might be an issue with an inefficiency in Shapefile.jl (what version of Shapefile.jl are you running?). Consider this addendum to your code:
julia> @time gb_geoms = GeoMakie.to_multipoly(countries2)
2.376218 seconds (4.12 M allocations: 139.941 MiB, 0.69% gc time)
julia> @time p1 = poly!(ax1, gb_geoms; color = :transparent, strokewidth = 1, strokecolor = :blue)
0.223099 seconds (103.81 k allocations: 66.597 MiB, 2.04% gc time, 24.87% compilation time)
Also, you should pass strokecolor
in poly to set the size of your lines.
With GeoIO the conversion of Shapefile.jl geometry to Meshes.jl geometry is eager, with Shapefile+GeoInterface it's lazy, only converting in poly
itself.
On #4319 I'm getting:
fig = nothing; fig = Figure(size = (900,900))
ax1 = Axis(fig[1,1])
@time p2 = poly!(ax1, countries2; color=(:blue,0.0), strokewidth = 0.75, overdraw = true)
0.421756 seconds (4.01 M allocations: 909.210 MiB, 9.01% gc time)
So maybe something that the refactor is fixing, even if it has gotten more memory hungry. (I guess GeometryBasics.merge(meshes)
could use some optimization...)
Additionally, the latter shows black contours instead of blue, but I may be doing it wrong.
Yes, you are setting the mesh color to transparent blue. You should set strokecolor = :blue
to get blue outlines.
After hunting down performance problems in merge(meshes):
@time p2 = poly!(ax1, countries2; color=(:blue,0.0), strokewidth = 0.75, overdraw = true)
0.200260 seconds (1.39 M allocations: 111.060 MiB)
This is the other major source of allocations. With the runtime type, Julia ends up allocating for every point here, I believe. With a function barrier that goes away. There should be more cases like this across the other interface methods, but maybe that's something the GeoInterface people should look into. I think these issues would also go away if you had something like get_type(::Vector{Point{N, T)) where {N, T} = T
in GeoInteface, for these geom types that are being passed around. Maybe that exists, or maybe it should?
After this change:
@time p2 = poly!(ax1, countries2; color=(:blue,0.0), strokewidth = 0.75, overdraw = true)
0.124739 seconds (15.11 k allocations: 67.517 MiB)
There's a proposal for that method in GeoInterface https://github.com/JuliaGeo/GeoInterface.jl/issues/128, we should probably get around to writing that...
Using the current version of Makie and Shapefile, still on Julia 1.10.5:
[e9467ef8] GLMakie v0.10.14
[db073c08] GeoMakie v0.7.5
[ee78f7c6] Makie v0.21.14
[8e980c4a] Shapefile v0.13.1
using GLMakie
using Shapefile
fig = nothing; fig = Figure(size = (900,900))
ax1 = Axis(fig[1,1])
countries = Shapefile.Handle(raw"C:\Users\oscar\Documents\Work\Julia\LMA\map\francespain.shp").shapes
@time poly!(ax1, countries; strokecolor=:blue, strokewidth = 1.25, overdraw = true)
3.227038 seconds (4.13 M allocations: 215.189 MiB, 1.72% gc time)
using GeoMakie
@time countries2 = GeoMakie.to_multipoly(countries);
2.908216 seconds (4.12 M allocations: 139.934 MiB, 0.25% gc time)
@time p2 = poly!(ax1, countries2; strokecolor=:blue, strokewidth = 1.25, overdraw = true)
0.236980 seconds (9.56 k allocations: 75.267 MiB, 10.12% gc time)
So, the situation is as in @asinghvi17 's comment, and using GeoMakie.to_multipoly
is fine. But the further speedup mentioned in the one before last comment has not arrived yet.
(I came back to this after getting a crash in my backup solution, GeoIO + Meshes: viz! It turns out that GeoIO was also preventing my update of many packages, so I'd rather not use it now)
pkg> add GeoIO
Resolving package versions...
⌅ [927a84f5] ↓ DelaunayTriangulation v1.6.1 ⇒ v0.8.12
⌃ [e9467ef8] ↓ GLMakie v0.10.14 ⇒ v0.8.12
⌃ [f5a160d5] + GeoIO v1.0.0
⌅ [61d90e0f] ↓ GeoJSON v0.8.1 ⇒ v0.7.3
⌃ [db073c08] ↓ GeoMakie v0.7.5 ⇒ v0.5.1
⌅ [5c1252a2] ↓ GeometryBasics v0.4.11 ⇒ v0.4.10
⌅ [3955a311] ↓ GridLayoutBase v0.11.0 ⇒ v0.9.2
⌅ [ee78f7c6] ↓ Makie v0.21.14 ⇒ v0.19.12
⌅ [20f20a25] ↓ MakieCore v0.8.9 ⇒ v0.6.9
⌅ [0a4f8689] ↓ MathTeXEngine v0.6.1 ⇒ v0.5.7
⌅ [eacbb407] + Meshes v0.34.12
⌅ [8e980c4a] ↓ Shapefile v0.13.1 ⇒ v0.10.0
]st -m Makie
) Makie v0.21.10 on Julia 1.10.5]activate --temp; add Makie
) not tried yet, but I did do a full] update
Today I tried to move from the use of GeoIO.jl + Meshes.viz! to draw a shapefile, to Shapefile.jl and Makie's own
poly!
The former method had a very similar latency inducing bug earlier which was fixed last May: https://discourse.julialang.org/t/visualization-of-shapefile-meshes-jl-viz-very-slowIt turns out that using
poly!
is taking more than 3 seconds and makes my Observables (toggles, menus, clicks, zooms etc) very laggy right from the start, to the point of crashing (see below). For now I will keep using my previous method, but I wanted to report this issue.shapefile.zip
Additionally, the latter shows black contours instead of blue, but I may be doing it wrong.
An error of the renderloop resulting from
poly!
: