After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 756548 - wayland-surface: disconnect signals on destroy
wayland-surface: disconnect signals on destroy
Status: RESOLVED FIXED
Product: mutter
Classification: Core
Component: wayland
unspecified
Other All
: Normal normal
: ---
Assigned To: mutter-maint
mutter-maint
Depends on:
Blocks:
 
 
Reported: 2015-10-14 04:34 UTC by Giovanni Campagna
Modified: 2015-10-20 00:22 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
wayland-surface: disconnect signals on destroy (2.96 KB, patch)
2015-10-14 04:34 UTC, Giovanni Campagna
none Details | Review
wayland-surface: disconnect signals on destroy (4.06 KB, patch)
2015-10-14 05:46 UTC, Giovanni Campagna
none Details | Review
wayland-surface: disconnect signals on destroy (4.06 KB, patch)
2015-10-14 05:48 UTC, Giovanni Campagna
none Details | Review
wayland-surface: disconnect signals on destroy (4.13 KB, patch)
2015-10-19 18:33 UTC, Giovanni Campagna
committed Details | Review

Description Giovanni Campagna 2015-10-14 04:34:50 UTC
Should fix https://retrace.fedoraproject.org/faf/reports/818490/
(but only compile tested because I don't have a working jhbuild session)
Comment 1 Giovanni Campagna 2015-10-14 04:34:53 UTC
Created attachment 313237 [details] [review]
wayland-surface: disconnect signals on destroy

Otherwise signal handlers will be called on garbage
Comment 2 Jasper St. Pierre (not reading bugmail) 2015-10-14 04:51:49 UTC
Review of attachment 313237 [details] [review]:

Hm, not g_signal_connect_object?
Comment 3 Giovanni Campagna 2015-10-14 05:23:05 UTC
(In reply to Jasper St. Pierre from comment #2)
> Review of attachment 313237 [details] [review] [review]:
> 
> Hm, not g_signal_connect_object?

You still want to disconnect when you change output, might as well disconnect when you're destroyed...
Comment 4 Jasper St. Pierre (not reading bugmail) 2015-10-14 05:31:59 UTC
I really don't like storing the signal ID in the hash map without renaming it. It seems unobvious and sketchy to me.
Comment 5 Giovanni Campagna 2015-10-14 05:46:04 UTC
Created attachment 313239 [details] [review]
wayland-surface: disconnect signals on destroy

Otherwise signal handlers will be called on garbage

Ok, I renamed the hash table. I would like to avoid
g_signal_handlers_disconnect_by_func because it's really slow.
Comment 6 Giovanni Campagna 2015-10-14 05:48:24 UTC
Created attachment 313240 [details] [review]
wayland-surface: disconnect signals on destroy

Otherwise signal handlers will be called on garbage

Ok, I renamed the hash table. I would like to avoid
g_signal_handlers_disconnect_by_func because it's really slow.
Comment 7 Jonas Ådahl 2015-10-15 03:37:09 UTC
(In reply to Giovanni Campagna from comment #6)
> Created attachment 313240 [details] [review] [review]
> wayland-surface: disconnect signals on destroy
> 
> Otherwise signal handlers will be called on garbage
> 
> Ok, I renamed the hash table. I would like to avoid
> g_signal_handlers_disconnect_by_func because it's really slow.

Will the speed of disconnect_by_func really ever be of any significance though? It's particularly insignificant when changing outputs since it's only one surface disconnecting from a single output. I don't really see any point from a performance perspective of doing this.

Anyway, assuming we still doing this, the name "outputs_to_signal" makes no sense to me, since there are no signals in the map. It's now a output_destroy_handler_ids map that double as a output set, so maybe just call it that?
Comment 8 Giovanni Campagna 2015-10-15 04:28:51 UTC
I've seen several slowdowns in various apps caused by g_signal_handlers_disconnect_by_func at the wrong time, so even though I can't measure it I think it's just a good idea to avoid it.

Now, I seem to recall that at some point it was O(n) in the total number of signal connections, not just the signal connections on the instance. That does not seem to be the case now, looking at the code, so maybe it's not that ugly.

(It is still linear on the number of connections on the output, which means that destroying an output would have cost quadratic on the number of windows on that output. Probably not a big deal: even with > 20 windows, at worst it might cause us to miss a frame.)

Nevertheless, I would prefer to use g_signal_handler_disconnect when it's easy enough, just as a matter of good practice.
But I'm not the maintainer of this code, so I'll stick to whatever you prefer - either a renamed hash table or the old disconnect_by_func.
Comment 9 Jonas Ådahl 2015-10-16 01:52:00 UTC
Review of attachment 313240 [details] [review]:

::: src/wayland/meta-wayland-surface.c
@@ +947,3 @@
+                             surface);
+      g_hash_table_replace (surface->outputs_to_signal, wayland_output,
+                            GSIZE_TO_POINTER ((gsize)id));

This should be a g_hash_table_insert right? Because we will never replace the entry, and if we did, we'd leak a handler.
Comment 10 Jonas Ådahl 2015-10-16 01:53:02 UTC
(In reply to Giovanni Campagna from comment #8)
> I've seen several slowdowns in various apps caused by
> g_signal_handlers_disconnect_by_func at the wrong time, so even though I
> can't measure it I think it's just a good idea to avoid it.
> 
> Now, I seem to recall that at some point it was O(n) in the total number of
> signal connections, not just the signal connections on the instance. That
> does not seem to be the case now, looking at the code, so maybe it's not
> that ugly.
> 
> (It is still linear on the number of connections on the output, which means
> that destroying an output would have cost quadratic on the number of windows
> on that output. Probably not a big deal: even with > 20 windows, at worst it
> might cause us to miss a frame.)
> 
> Nevertheless, I would prefer to use g_signal_handler_disconnect when it's
> easy enough, just as a matter of good practice.
> But I'm not the maintainer of this code, so I'll stick to whatever you
> prefer - either a renamed hash table or the old disconnect_by_func.

I'm not a maintainer either, and since you are the one writing the code, I'd say lets go with your approach. I'd only prefer not having something else than "to_signal" as a prefix only because the map has no signals.
Comment 11 Giovanni Campagna 2015-10-16 06:24:06 UTC
(In reply to Jonas Ådahl from comment #9)
> Review of attachment 313240 [details] [review] [review]:
> 
> ::: src/wayland/meta-wayland-surface.c
> @@ +947,3 @@
> +                             surface);
> +      g_hash_table_replace (surface->outputs_to_signal, wayland_output,
> +                            GSIZE_TO_POINTER ((gsize)id));
> 
> This should be a g_hash_table_insert right? Because we will never replace
> the entry, and if we did, we'd leak a handler.

insert and replace are the same thing, they only differ in the memory management of the key
Comment 12 Jonas Ådahl 2015-10-16 07:37:08 UTC
(In reply to Giovanni Campagna from comment #11)
> (In reply to Jonas Ådahl from comment #9)
> > Review of attachment 313240 [details] [review] [review] [review]:
> > 
> > ::: src/wayland/meta-wayland-surface.c
> > @@ +947,3 @@
> > +                             surface);
> > +      g_hash_table_replace (surface->outputs_to_signal, wayland_output,
> > +                            GSIZE_TO_POINTER ((gsize)id));
> > 
> > This should be a g_hash_table_insert right? Because we will never replace
> > the entry, and if we did, we'd leak a handler.
> 
> insert and replace are the same thing, they only differ in the memory
> management of the key

Sure, but I was more talking about readability here. And I guess since it's guaranteed that we will never have an entry here, the memory management would effectively be the same as well?
Comment 13 Giovanni Campagna 2015-10-19 18:33:04 UTC
Created attachment 313693 [details] [review]
wayland-surface: disconnect signals on destroy

Otherwise signal handlers will be called on garbage
Comment 14 Jonas Ådahl 2015-10-20 00:09:01 UTC
Review of attachment 313693 [details] [review]:

Looks good to me.
Comment 15 Giovanni Campagna 2015-10-20 00:22:40 UTC
Attachment 313693 [details] pushed as a4f763a - wayland-surface: disconnect signals on destroy