[glib/gobject-performance: 6/10] Don't freeze/thaw notification during construction if no properties



commit ce37833d314a34b13449be85f6c2e56a35a38be3
Author: Alexander Larsson <alexl redhat com>
Date:   Wed Aug 19 17:22:32 2009 +0200

    Don't freeze/thaw notification during construction if no properties
    
    If the class has no properties there could be no notification anyway.
    This is an important optimization for construction of simple objects.
    
    Object construction performance improvement:
             Non-Threaded   Threaded
    Simple:           84%        91%
    Complex:        -1.4%      -0.6%
    
    Other tests stable.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=557100

 gobject/gobject.c |   37 +++++++++++++++++++++++++------------
 1 files changed, 25 insertions(+), 12 deletions(-)
---
diff --git a/gobject/gobject.c b/gobject/gobject.c
index d7d5d56..9490fed 100644
--- a/gobject/gobject.c
+++ b/gobject/gobject.c
@@ -134,7 +134,8 @@ enum {
 static void	g_object_base_class_init		(GObjectClass	*class);
 static void	g_object_base_class_finalize		(GObjectClass	*class);
 static void	g_object_do_class_init			(GObjectClass	*class);
-static void	g_object_init				(GObject	*object);
+static void	g_object_init				(GObject	*object,
+							 GObjectClass	*class);
 static GObject*	g_object_constructor			(GType                  type,
 							 guint                  n_construct_properties,
 							 GObjectConstructParam *construct_params);
@@ -688,13 +689,18 @@ g_object_interface_list_properties (gpointer      g_iface,
 }
 
 static void
-g_object_init (GObject *object)
+g_object_init (GObject		*object,
+	       GObjectClass	*class)
 {
   object->ref_count = 1;
   g_datalist_init (&object->qdata);
-  
-  /* freeze object's notification queue, g_object_newv() preserves pairedness */
-  g_object_notify_queue_freeze (object, &property_notify_context);
+
+  if (CLASS_HAS_PROPS (class))
+    {
+      /* freeze object's notification queue, g_object_newv() preserves pairedness */
+      g_object_notify_queue_freeze (object, &property_notify_context);
+    }
+
   /* enter construction list for notify_queue_thaw() and to allow construct-only properties */
   G_LOCK (construction_mutex);
   construction_objects = g_slist_prepend (construction_objects, object);
@@ -1229,10 +1235,14 @@ g_object_newv (GType       object_type,
   G_LOCK (construction_mutex);
   newly_constructed = slist_maybe_remove (&construction_objects, object);
   G_UNLOCK (construction_mutex);
-  if (newly_constructed || n_oparams)
-    nqueue = g_object_notify_queue_freeze (object, &property_notify_context);
-  if (newly_constructed)
-    g_object_notify_queue_thaw (object, nqueue);
+
+  if (CLASS_HAS_PROPS (class))
+    {
+      if (newly_constructed || n_oparams)
+	nqueue = g_object_notify_queue_freeze (object, &property_notify_context);
+      if (newly_constructed)
+	g_object_notify_queue_thaw (object, nqueue);
+    }
 
   /* run 'constructed' handler if there is one */
   if (newly_constructed && class->constructed)
@@ -1243,9 +1253,12 @@ g_object_newv (GType       object_type,
     object_set_property (object, oparams[i].pspec, oparams[i].value, nqueue);
   g_free (oparams);
 
-  /* release our own freeze count and handle notifications */
-  if (newly_constructed || n_oparams)
-    g_object_notify_queue_thaw (object, nqueue);
+  if (CLASS_HAS_PROPS (class))
+    {
+      /* release our own freeze count and handle notifications */
+      if (newly_constructed || n_oparams)
+	g_object_notify_queue_thaw (object, nqueue);
+    }
 
   if (unref_class)
     g_type_class_unref (unref_class);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]