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

Slow and excessive allocation in density and xticks #4608

Open
Moelf opened this issue Nov 20, 2024 · 1 comment · May be fixed by #4681
Open

Slow and excessive allocation in density and xticks #4608

Moelf opened this issue Nov 20, 2024 · 1 comment · May be fixed by #4681
Labels
Axis related to `Axis()` objects bug Makie Backend independent issues (Makie core)

Comments

@Moelf
Copy link
Contributor

Moelf commented Nov 20, 2024

using CairoMakie

@time begin
    fig = Figure(size=(800, 400))
    ax = Axis(fig[1,1]; title="inclusive", 
        # xticks=0:50:500,
        yscale=log10)
    barplot!(ax, 50:50:200, fill(15, 4))
    density!(ax, [-1e9];color = (:blue, 0.1), strokecolor = :darkblue, strokewidth = 0.7, label="MC Combination")
    display(fig)
end
#  0.106324 seconds (119.25 k allocations: 15.332 MiB)


@time begin
    fig = Figure(size=(800, 400))
    ax = Axis(fig[1,1]; title="inclusive", 
        xticks=0:50:500,
        yscale=log10)
    barplot!(ax, 50:50:200, fill(15, 4))
    density!(ax, [-1e9];color = (:blue, 0.1), strokecolor = :darkblue, strokewidth = 0.7, label="MC Combination")
    display(fig)
end
# 5.600610 seconds (78.40 k allocations: 11.603 GiB, 12.51% gc time)

cc. @sfranchel this means we shouldn't use the density!() to "fake" a legend element...

@Moelf Moelf added the bug label Nov 20, 2024
@ffreyer
Copy link
Collaborator

ffreyer commented Dec 16, 2024

This is caused by minorticks. They see a step width of 50 from the xticks you set and xlims of -1e9 .. 220 from the plots you create. So they think the (major) ticks are -1e9:50:220, which is 20 million values, each getting 2 ticks. (Technically there is also padding on autolimits so it ends up being a bit more.)

The user side fix would be to call xlims!() before displaying, or set xautolimits = false for the density plot.

@ffreyer ffreyer added Makie Backend independent issues (Makie core) Axis related to `Axis()` objects labels Dec 16, 2024
@ffreyer ffreyer linked a pull request Dec 18, 2024 that will close this issue
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Axis related to `Axis()` objects bug Makie Backend independent issues (Makie core)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants