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 603590 - Speed up G_VALUE_COLLECT
Speed up G_VALUE_COLLECT
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: gobject
unspecified
Other All
: Normal enhancement
: ---
Assigned To: gtkdev
gtkdev
: 607293 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2009-12-02 12:47 UTC by Edward Hervey
Modified: 2010-01-18 15:22 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
gvaluecollector: Add variant of G_VALUE_COLLECT for most used cases. (3.89 KB, patch)
2009-12-02 12:48 UTC, Edward Hervey
none Details | Review
gsignal: Use new G_VALUE_COLLECT_FULL variant (2.11 KB, patch)
2009-12-02 12:48 UTC, Edward Hervey
none Details | Review
gobject: Use new G_VALUE_COLLECT_FULL variant (1.54 KB, patch)
2009-12-02 12:48 UTC, Edward Hervey
none Details | Review
gvaluecollector: Add variant of G_VALUE_COLLECT for most used cases. (4.03 KB, patch)
2009-12-28 14:58 UTC, Edward Hervey
none Details | Review
gvaluecollector: Add variant of G_VALUE_COLLECT for most used cases. (4.03 KB, patch)
2009-12-28 15:01 UTC, Edward Hervey
none Details | Review
gsignal: Use new G_VALUE_COLLECT_INIT variant (2.11 KB, patch)
2009-12-28 15:01 UTC, Edward Hervey
none Details | Review
gobject: Use new G_VALUE_COLLECT_INIT variant (1.54 KB, patch)
2009-12-28 15:01 UTC, Edward Hervey
none Details | Review
Ensure values are memset to 0 when calling G_VALUE_COLLECT_INIT() (2.49 KB, patch)
2010-01-18 13:46 UTC, Benjamin Otte (Company)
committed Details | Review

Description Edward Hervey 2009-12-02 12:47:57 UTC
G_VALUE_COLLECT is being used extensively when creating new GObject and emitting signals.

The problem is that the current usage goes as such:

g_value_init
  => calls g_type_value_table_peek()
  => initializes memory
  => calls ->value_init
G_VALUE_COLLECT
  => calls g_type_value_table_peek() AGAIN
  => if present, frees the memory (wait, it's BLANK !)
  => initializes memory again


The following patches create a new G_VALUE_COLLECT_FULL variant which initializes/sets the GValue in one go. This brings a 15-20% speedup to g_object_new_valist and g_signal_emit_valist
Comment 1 Edward Hervey 2009-12-02 12:48:37 UTC
Created attachment 148901 [details] [review]
gvaluecollector: Add variant of G_VALUE_COLLECT for most used cases.

Most callers of G_VALUE_COLLECT previously had to initialize the GValue
and then G_VALUE_COLLECT would still go through a cleanup phase.

The new variant allows passing a unitialized GValue along with a GType
and speedup the initialization/collection process.
Comment 2 Edward Hervey 2009-12-02 12:48:41 UTC
Created attachment 148902 [details] [review]
gsignal: Use new G_VALUE_COLLECT_FULL variant

Makes g_signal_emit_valist from 15% to 20% faster.

Results reported from profiling the pan newsreader which uses a variant
of simple and complex signal emissions (i.e no args or various args)
Comment 3 Edward Hervey 2009-12-02 12:48:49 UTC
Created attachment 148903 [details] [review]
gobject: Use new G_VALUE_COLLECT_FULL variant

Makes g_object_new_valist 20% to 30% faster (against 2321e5a).

Profiled against the pan newsreader which uses a variant of simple
and complex object creation.
Comment 4 Benjamin Otte (Company) 2009-12-02 13:01:10 UTC
I like this patch. Some comments about it (mostly from discussing on IRC):

- G_VALUE_COLLECT_FULL() is a bad name. I don't know a better one though. Maybe G_VALUE_COLLECT_TYPE()?

- Your docs say the value must be empty. If it has to be empty, we don't need to do the memset manually. We only need to do it if we say that value may point to random memory. In those cases, we don't need to pre-initialize the values in gsignal.c/gobject.c though. I have no strong opinion either way, but I think I'd prefer keeping the docs and moving the memset to G_VALUE_COLLECT().

- Edward mentioned on IRC that the performance metrics come from using valgrind counting instructions. Just thought I should mention that here.
Comment 5 Alexander Larsson 2009-12-02 13:09:36 UTC
The name is quite bad, xxx_FULL in glib apis generally means it takes more arguments than the non-full version and otherwise have the same behaviour. However, the behaviour here is different.

What about combining init and collect, like G_VALUE_COLLECT_INIT()?
Comment 6 Edward Hervey 2009-12-28 14:58:50 UTC
Created attachment 150496 [details] [review]
gvaluecollector: Add variant of G_VALUE_COLLECT for most used cases.

Most callers of G_VALUE_COLLECT previously had to initialize the GValue
and then G_VALUE_COLLECT would still go through a cleanup phase.

The new variant allows passing a unitialized GValue along with a GType
and speedup the initialization/collection process.
Comment 7 Edward Hervey 2009-12-28 15:01:27 UTC
Created attachment 150497 [details] [review]
gvaluecollector: Add variant of G_VALUE_COLLECT for most used cases.

Most callers of G_VALUE_COLLECT previously had to initialize the GValue
and then G_VALUE_COLLECT would still go through a cleanup phase.

The new variant allows passing a unitialized GValue along with a GType
and speedup the initialization/collection process.
Comment 8 Edward Hervey 2009-12-28 15:01:39 UTC
Created attachment 150498 [details] [review]
gsignal: Use new G_VALUE_COLLECT_INIT variant

Makes g_signal_emit_valist from 15% to 20% faster.

Results reported from profiling the pan newsreader which uses a variant
of simple and complex signal emissions (i.e no args or various args)
Comment 9 Edward Hervey 2009-12-28 15:01:44 UTC
Created attachment 150499 [details] [review]
gobject: Use new G_VALUE_COLLECT_INIT variant

Makes g_object_new_valist 20% to 30% faster (against 2321e5a).

Profiled against the pan newsreader which uses a variant of simple
and complex object creation.
Comment 10 Edward Hervey 2009-12-28 15:03:01 UTC
Changes of the above 3 patches:
* renamed to G_VALUE_COLLECT_INIT
* move the meminit to G_VALUE_COLLECT

Comments welcome.
Comment 11 Alexander Larsson 2010-01-11 14:54:14 UTC
Review of attachment 150497 [details] [review]:

::: gobject/gvaluecollector.h
@@ +83,3 @@
  * va_list variables cannot be passed by reference.
+ *
+ * Since: 2.23.1

Generally we put since 2.24 (ie next major release)

@@ +141,3 @@
+ *
+ * Note: If you are creating the @value argument just before calling this macro,
+ * you should use the #G_VALUE_COLLECT_FULL variant and pass the unitialized

This references the old name of the macro
Comment 12 Alexander Larsson 2010-01-11 14:56:12 UTC
Otherwise this looks good to me
Comment 13 Alexander Larsson 2010-01-11 15:06:39 UTC
G_VALUE_INIT_AND_COLLECT was also proposed as a name, not sure which is best.
Comment 14 Alexander Larsson 2010-01-13 09:27:08 UTC
I fixed the things i commented on above and commited. This seems obviously safe and better, so no need to keep it waiting.
Comment 15 Philippe Normand 2010-01-18 11:58:18 UTC
This patch introduces a bug in GStreamer, see https://bugzilla.gnome.org/show_bug.cgi?id=607283
Comment 16 Sebastian Dröge (slomo) 2010-01-18 12:29:53 UTC
*** Bug 607283 has been marked as a duplicate of this bug. ***
Comment 17 Sebastian Dröge (slomo) 2010-01-18 12:34:43 UTC
Problem might be, that in commit 0f25115f the GValues are not really initialized but are only allocated by g_slice_alloc(), i.e. they contain random data.
Comment 18 Benjamin Otte (Company) 2010-01-18 12:50:10 UTC
Gah, the value_init docs say that the value will be memset to zeros, so I guess we should keep that guarantee.
Still, those same docs also say no care must be taken to remove any old values, so I'd suggest making gst_mini_object_collect() not try to delete a nonexisting old value by using _replace().
Comment 19 Sebastian Dröge (slomo) 2010-01-18 12:54:43 UTC
Yeah, I just noticed the same. I'll fix the mini object collect function
Comment 20 Benjamin Otte (Company) 2010-01-18 13:46:56 UTC
Created attachment 151666 [details] [review]
Ensure values are memset to 0 when calling G_VALUE_COLLECT_INIT()

The reason we need to enforce this is that the GTypeValueTable
documentation explicitly states that memory is memset to 0 when the
value_init function is called.
Comment 21 Edward Hervey 2010-01-18 14:18:11 UTC
*** Bug 607293 has been marked as a duplicate of this bug. ***
Comment 22 Matthias Clasen 2010-01-18 15:06:11 UTC
Comment on attachment 151666 [details] [review]
Ensure values are memset to 0 when calling G_VALUE_COLLECT_INIT()

Please commit
Comment 23 Benjamin Otte (Company) 2010-01-18 15:22:30 UTC
Comment on attachment 151666 [details] [review]
Ensure values are memset to 0 when calling G_VALUE_COLLECT_INIT()

landed as 914120b9701650ccf7bede1907b69b521ca43236