Skip to content

Instantly share code, notes, and snippets.

@SimonDanisch
Last active June 23, 2025 13:55
Show Gist options
  • Save SimonDanisch/bda7660ebfebab5a9a090b16433c31dc to your computer and use it in GitHub Desktop.
Save SimonDanisch/bda7660ebfebab5a9a090b16433c31dc to your computer and use it in GitHub Desktop.
Benchmarking Makie v0.24 against v0.23
using WGLMakie, Bonito
MSGS = Dict()
function run_example!(figfunc, name, testfunc)
f, ax, pl = figfunc()
display(f)
_testfunc() = begin
testfunc(f, ax, pl)
if isdefined(WGLMakie, :poll_all_plots)
WGLMakie.poll_all_plots(f.scene)
else
sleep(0.1)
end
end
_testfunc()
_testfunc()
msgs, msg = Bonito.collect_messages(_testfunc)
return MSGS[name] = (msgs, msg)
end
run_example!("resize!", (f, ax, pl) -> resize!(f, rand(500:1000), rand(500:1000))) do
f = Figure(size = (800, 800))
for i in 1:3, j in 1:3
if isodd(i + j)
heatmap(f[i, j], rand(500, 500))
else
scatter(f[i, j], rand(10), rand(10); color = rand(10))
end
end
return f, nothing, nothing
end
if !isdefined(Makie, :update!)
function update_plots(f, ax, pl)
pl.color = rand(1000)
pl.colormap = rand(Makie.all_gradient_names)
return pl.markersize = rand(5:0.001:60)
end
else
function update_plots(f, ax, pl)
return update!(pl, color = rand(1000), colormap = rand(Makie.all_gradient_names), markersize = rand(5:0.001:60))
end
end
run_example!("update!", update_plots) do
return scatter(rand(Point2f, 1000); color = rand(1000), colormap = :turbo, markersize = 20)
end
function trigger_update(f, ax, pl)
e = events(f)
e.mouseposition[] = (300, 250)
e.mousebutton[] = Makie.MouseButtonEvent(Mouse.right, Mouse.press)
e.mouseposition[] = (350, 250)
return e.mousebutton[] = Makie.MouseButtonEvent(Mouse.right, Mouse.release)
end
run_example!("zoom interaction", trigger_update) do
return scatter(rand(Point2f, 1000); color = rand(1000), colormap = :turbo, markersize = 20)
end
run_example!("Axis3", (f, ax, pl) -> (ax.azimuth = rand(-π:0.001:π))) do
return meshscatter(rand(Point3f, 100), axis = (; type = Axis3))
end
run_example!("Axis3 hidden", (f, ax, pl) -> (ax.azimuth = rand(-π:0.001:π))) do
f, ax, pl = meshscatter(rand(Point3f, 100), axis = (; type = Axis3))
hidedecorations!(ax)
return f, ax, pl
end
begin
result = Dict{String, Any}()
for (k, val) in MSGS
msgs = val[1]
len = length(msgs)
size_b = sum(map(Base.summarysize, msgs))
result[k] = (len, size_b)
end
result
end
### Plotting
result = Dict{String, Any}(
"zoom interaction" => (5, 8754),
"resize!" => (265, 345766),
"Axis3" => (35, 49101),
"update!" => (1, 6200),
"Axis3 hidden" => (18, 22891)
)
result_tagged = Dict{String, Any}(
"zoom interaction" => (24, 33832),
"resize!" => (1445, 1906818),
"Axis3" => (263, 352985),
"update!" => (7, 11984),
"Axis3 hidden" => (155, 204002)
)
using DataFrames, AlgebraOfGraphics, CairoMakie
tnames = collect(keys(result_tagged))
category = [tnames..., tnames...]
version = [fill("v0.23", length(tnames))..., fill("v0.24", length(tnames))...]
num_messages = map(zip(category, version)) do (cat, ver)
if ver == "v0.24"
result[cat][1]
else
result_tagged[cat][1]
end
end
size_messages = map(zip(category, version)) do (cat, ver)
if ver == "v0.24"
result[cat][2]
else
result_tagged[cat][2]
end
end
begin
df = DataFrame(
category = category,
version = version,
num_messages = num_messages,
message_size = size_messages
)
df.num_messages_rel = df.num_messages ./ repeat(df.num_messages[1:5], 2) .* 100
df.message_size_rel = df.message_size ./ repeat(df.message_size[1:5], 2) .* 100
df2 = stack(df, [:num_messages_rel, :message_size_rel])
df.num_messages = string.(df.num_messages)
df.message_size = string.(round.(Int, df.message_size ./ 1024), " KiB")
df2.label = stack(df, [:num_messages, :message_size]).value
f = data(df2) * mapping(
:category => "", :value => "", color = :version,
layout = :variable => renamer(["message_size_rel" => "Message size", "num_messages_rel" => "Number of messages"]), bar_labels = :label => verbatim,
) * visual(BarPlot, label_offset = 2, label_size = 12) |>
draw(
scales(
Color = (; palette = [:lightgreen, :tomato1]),
Layout = (; palette = wrapped(cols = 1))
);
axis = (;
yautolimitmargin = (0, 0.2),
xgridvisible = false,
ygridvisible = false,
topspinevisible = false,
rightspinevisible = false,
yticklabelsvisible = false,
yticksvisible = false,
leftspinevisible = false,
),
legend = (; framevisible = false),
figure = (; title = "Reduction in network traffic from v0.23 to v0.24", titlealign = :center),
)
save("wglmakie-benchmark.svg", f)
f
end
@SimonDanisch
Copy link
Author

wglmakie-benchmark

@SimonDanisch
Copy link
Author

wglmakie-benchmark

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment