GNOME Bugzilla – Bug 418970
Avoid trivial allocations during g_object_notify()
Last modified: 2014-12-22 17:58:23 UTC
1. GObjectNotifyQueue abuses the GList allocator, however GSlice obsoletes that and supplies a generic allocator perfect for use here... 2. Frequently g_object_notify() is run immediately (e.g. the GtkAdjustment emitting value-changed...) and so only has a single member in its list. We can avoid the allocation overhead here and embed one GSLink into the NotifyQueue struct. Does GObjectNotifyQueue count as a public ABI since the .c file (and its "private" definitions) is #included into other projects?
Created attachment 84714 [details] [review] Avoid trivial allocs in g_object_notify()
Hmm, missed one controversial aspect of that patch - it delays the free of the GObjectNotifyQueue til object destruction rather than recreating a new GObjectNotifyQueue for each g_object_notify()
Looks good. Wonder what the glib maintainers think about it.
I fail to see an obvious improvement in this patch. Granted, the current code should be mildly cleaned up to use GSlice instead of the list allocator functions at this point. However, trying to "save" the initial list node allocation in the pspec queue is quite pointless in my eyes, because GSlice already gives us a fast portable allocation mechanism (for the most part, allocating a list node amounts to popping a node from a per-thread free list) and it obfuscates the list handling (apart from failing to free the notification queue as comment #2 points out). It'd be interesting so see any benchmarks that back the idea that this could have a *significant* performance impact.
Perhaps a patch that only changes the code to use GSlice would be a good start? Based on that, additional improvements can be benchmarked and discussed then.
the code in gobjectnotifyqueue.c was merged inside gobject.c in commit: commit 128862eafe49b5454c4b32b0866800d4aa7c53f3 Author: Ryan Lortie <desrt@desrt.ca> Date: Wed Nov 16 15:31:58 2011 +0000 [notify] merge gobjectnotifyqueue.c into gobject.c and the code cleaned up. gobjectnotifyqueue.c is still available because it's included directly by other projects, but it won't see any further changes.