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

Call empty! in block deletion #2614

Merged
merged 1 commit into from
Jan 19, 2023
Merged

Call empty! in block deletion #2614

merged 1 commit into from
Jan 19, 2023

Conversation

ffreyer
Copy link
Collaborator

@ffreyer ffreyer commented Jan 19, 2023

Description

See https://discourse.julialang.org/t/removing-row-from-gridlayout/93196

Still shouldn't completely clean up a block, but remove plots and a decent chunk of observables.

Add a description of your PR here.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

@jkrumbiegel
Copy link
Member

At some point we should add tests that check that a block and the relevant scenes, plots, etc. can be garbage collected once they're deleted. I assume unless the last observable connection is severed, that's not possible.

@ffreyer
Copy link
Collaborator Author

ffreyer commented Jan 19, 2023

The example from discourse still has a wild amount of listeners in fig.scene.px_area if you remove all blocks with this.

Makie.jl/src/scenes.jl

Lines 177 to 182 in 94b5ec5

on(events.window_area, priority = typemax(Int)) do w_area
if !any(x -> x 0.0, widths(w_area)) && px_area[] != w_area
px_area[] = w_area
end
return Consume(false)
end
might be partially to blame since on doesn't add to obs.inputs? Though most listeners seem to be maps from

Makie.jl/src/scenes.jl

Lines 240 to 248 in 94b5ec5

if isnothing(px_area)
px_area = lift(zero_origin, parent.px_area; ignore_equal_values=true)
else
px_area = lift(pixelarea(parent), convert(Observable, px_area); ignore_equal_values=true) do p, a
# make coordinates relative to parent
rect = Rect2i(minimum(p) .+ minimum(a), widths(a))
return rect
end
end
which should show up, I think, but don't in any block.blockscene.px_area.inputs?

@jkrumbiegel
Copy link
Member

Yes, px_area and scene.camera.projectionview are lifted all over the place.

@ffreyer
Copy link
Collaborator Author

ffreyer commented Jan 19, 2023

scene.events are also kind of a nightmare to clean up atm, since the events struct is shared between all scenes. So you can't just empty all listeners there and call it a day. You also can't have child.events.x = map(identity, parent.events.x) because it would mess up priority.
Maybe we could add some wrapper that keeps track of where listeners have been added, but still adds them to the scene-global events? I.e.

struct LocalEvents
    global_events::Events
    local_obsfuncs::Vector{Function}
end

that adds to local_obs_funcs on map, on, etc? That could then do off.(local_obsfuncs) when empty!(scene) is called (for each child scene as well).

I think I'll give this a try later today.

@MakieBot
Copy link
Collaborator

MakieBot commented Jan 19, 2023

Compile Times benchmark

Note, that these numbers may fluctuate on the CI servers, so take them with a grain of salt. All benchmark results are based on the mean time and negative percent mean faster than the base branch. Note, that GLMakie + WGLMakie run on an emulated GPU, so the runtime benchmark is much slower. Results are from running:

using_time = @ctime using Backend
# Compile time
create_time = @ctime fig = scatter(1:4; color=1:4, colormap=:turbo, markersize=20, visible=true)
display_time = @ctime Makie.colorbuffer(display(fig))
# Runtime
create_time = @benchmark fig = scatter(1:4; color=1:4, colormap=:turbo, markersize=20, visible=true)
display_time = @benchmark Makie.colorbuffer(display(fig))
using create display create display
GLMakie 31.64s (28.91, 32.22) 1.21+- 16.30s (16.10, 16.56) 0.14+- 15.22s (15.13, 15.45) 0.11+- 11.77ms (11.68, 11.83) 0.06+- 133.39ms (130.95, 135.32) 1.38+-
master 32.25s (32.16, 32.37) 0.06+- 16.34s (16.25, 16.50) 0.09+- 15.29s (15.16, 15.44) 0.10+- 11.81ms (11.71, 11.88) 0.06+- 134.20ms (131.33, 135.65) 1.37+-
evaluation -1.92%, -0.61s invariant (-0.71d, 0.23p, 0.64std) -0.28%, -0.05s invariant (-0.39d, 0.48p, 0.11std) -0.43%, -0.06s invariant (-0.61d, 0.27p, 0.11std) -0.35%, -0.04ms invariant (-0.68d, 0.23p, 0.06std) -0.61%, -0.82ms invariant (-0.59d, 0.29p, 1.38std)
CairoMakie 26.06s (25.86, 26.27) 0.15+- 16.41s (16.26, 16.72) 0.18+- 2.53s (2.50, 2.58) 0.03+- 10.59ms (10.44, 10.95) 0.18+- 4.17ms (4.07, 4.35) 0.11+-
master 26.12s (25.80, 26.48) 0.22+- 16.46s (16.16, 16.82) 0.24+- 2.53s (2.48, 2.59) 0.04+- 10.62ms (10.38, 10.82) 0.13+- 4.18ms (4.03, 4.34) 0.11+-
evaluation -0.23%, -0.06s invariant (-0.31d, 0.57p, 0.19std) -0.32%, -0.05s invariant (-0.25d, 0.65p, 0.21std) -0.14%, -0.0s invariant (-0.10d, 0.86p, 0.03std) -0.22%, -0.02ms invariant (-0.15d, 0.78p, 0.15std) -0.24%, -0.01ms invariant (-0.09d, 0.87p, 0.11std)
WGLMakie 39.32s (38.73, 39.94) 0.43+- 20.40s (20.15, 20.99) 0.29+- 24.67s (24.40, 25.14) 0.26+- 16.50ms (15.81, 17.21) 0.49+- 2.38s (2.22, 2.52) 0.11+-
master 39.35s (39.12, 39.63) 0.19+- 20.52s (20.32, 20.80) 0.15+- 24.49s (24.37, 24.61) 0.07+- 16.84ms (16.58, 17.19) 0.21+- 2.39s (2.09, 2.52) 0.15+-
evaluation -0.08%, -0.03s invariant (-0.10d, 0.86p, 0.31std) -0.58%, -0.12s invariant (-0.52d, 0.35p, 0.22std) +0.73%, 0.18s invariant (0.93d, 0.13p, 0.17std) -2.01%, -0.33ms invariant (-0.87d, 0.14p, 0.35std) -0.38%, -0.01s invariant (-0.07d, 0.90p, 0.13std)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants