MakieOrg / Makie.jl

Interactive data visualizations and plotting in Julia
https://docs.makie.org/stable
MIT License
2.41k stars 312 forks source link

axislegend() unreasonable number of allocations #4052

Closed bertini97 closed 2 months ago

bertini97 commented 3 months ago

The profiler told me most of the allocations in my long script came from axislegend() and I didn't want to believe it, but upon closer benchmarking it apparently is the source of a huge number of allocations

using CairoMakie
using BenchmarkTools

fig = Figure()
ax = Axis(fig[1,1])
lines!(ax, (1:1:10), label="x")
@btime axislegend($ax)
4.353 ms (27570 allocations: 1.32 MiB)
jkrumbiegel commented 3 months ago

Legend code is relatively complex, so I'm not surprised it allocates quite a bit. If you're motivated to optimize things, I'm happy about a PR.

But I think if you btime the call then it will add many legends to a single figure and this will probably in itself get slower and slower

bertini97 commented 3 months ago

Ah, bummer. I hoped it was some obvious bug. Right now, I don't know where to look for. Should I close the issue?

jkrumbiegel commented 3 months ago

Yeah I think then it doesn't sound actionable or concrete enough.