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 731892 - gstvalue: Avoid expensive g_type_check_value_holds calls when dealing with fundamental GType
gstvalue: Avoid expensive g_type_check_value_holds calls when dealing with fu...
Status: RESOLVED FIXED
Product: GStreamer
Classification: Platform
Component: gstreamer (core)
unspecified
Other All
: Normal enhancement
: 1.3.3
Assigned To: GStreamer Maintainers
GStreamer Maintainers
Depends on: 731756
Blocks: 731829
 
 
Reported: 2014-06-19 05:23 UTC by Edward Hervey
Modified: 2014-06-20 10:27 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
gstvalue: Check GValue type directly for fundamentals (4.36 KB, patch)
2014-06-19 05:56 UTC, Edward Hervey
needs-work Details | Review

Description Edward Hervey 2014-06-19 05:23:54 UTC
+++ This bug was initially created as a clone of Bug #731756 +++

The follow up of the upstream bug is that when dealing with fundamental type gvalue (which is.... er.... all our basic types), we can just avoid calling G_VALUE_HOLDS altogether and instead just do a simple (v && (G_VALUE_TYPE(v) == type))
Comment 1 Edward Hervey 2014-06-19 05:56:02 UTC
Created attachment 278731 [details] [review]
gstvalue: Check GValue type directly for fundamentals

When wanting to check whether a GValue is of a certain fundamental
type, we can just check directly the GValue type instead of doing
a more expensive G_VALUE_HOLDS (which calls g_type_check_value_holds())

Benchmark:
 * valgrind callgrind (instruction calls):
 gst_value_compare: 48% to 58% of the calls (70 to 100% speedup)
 gst_value_subtract: 62% to 79% of the calls (27 to 60% speedup)
 gst_value_intersect: 51% to 60% of the calls (66 to 94% speedup)
Comment 2 Sebastian Dröge (slomo) 2014-06-20 10:14:46 UTC
Review of attachment 278731 [details] [review]:

::: gst/gstvalue.c
@@ +44,3 @@
 #include "gstutils.h"
 
+#define GST_VALUE_HOLDS_FUNDAMENTAL(v,t) ((v) && ((v)->g_type == t))

GST_VALUE_HOLDS_EXACTLY() instead maybe? Fundamental values can have subtypes


Also you might want to use that for G_TYPE_INT, _STRING, other basic types too. All over the file.

In theory they can have subtypes but we don't support that currently either
Comment 3 Tim-Philipp Müller 2014-06-20 10:27:29 UTC
I think this is obsolete now:

commit 6880844d8a9a0d4cd1703e5d197ee3ae2cc20819
Author: Tim-Philipp Müller <tim@centricular.com>
Date:   Tue Jun 17 22:45:57 2014 +0100

    value: simplify GST_VALUE_HOLDS for our boxed and fundamental types
    
    Boxed types can't be derived from, and we don't support
    deriving from our special fundamental types (the code
    checks for GType equality in most places.

commit bc75a166f01d7e75b0990f17b9f85fad9ad8585f
Author: Tim-Philipp Müller <tim@centricular.com>
Date:   Thu Jun 19 08:09:55 2014 +0100

    gstvalue: optimise checks for lists
    
    Our fundamental types are non-derivable, so we can
    just check for equality. Also avoid doing the same
    check multiple times in a couple of places.

(sorry for the duplicate work, but I had been working on that already, just hadn't pushed it yet because of the unit tests needing fixing for the compiler warning)