[glib/gobject-performance: 7/12] Add fast path for construction with no params



commit 723c5afe177ec93cb9cd591b43d7a094ff3e71c5
Author: Alexander Larsson <alexl redhat com>
Date:   Wed Aug 19 17:24:16 2009 +0200

    Add fast path for construction with no params
    
    This avoids a bunch of code and makes construction of simple objects
    faster.
    
    Object construction performance improvement:
             Non-Threaded   Threaded
    Simple:           14%         5%
    Complex:        -1.1%      -2.2%
    
    Other tests stable.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=557100

 gobject/gobject.c |   14 +++++++++++++-
 1 files changed, 13 insertions(+), 1 deletions(-)
---
diff --git a/gobject/gobject.c b/gobject/gobject.c
index 9490fed..102652d 100644
--- a/gobject/gobject.c
+++ b/gobject/gobject.c
@@ -1125,7 +1125,7 @@ g_object_newv (GType       object_type,
 	       guint       n_parameters,
 	       GParameter *parameters)
 {
-  GObjectConstructParam *cparams, *oparams;
+  GObjectConstructParam *cparams = NULL, *oparams;
   GObjectNotifyQueue *nqueue = NULL; /* shouldn't be initialized, just to silence compiler */
   GObject *object;
   GObjectClass *class, *unref_class = NULL;
@@ -1147,6 +1147,17 @@ g_object_newv (GType       object_type,
       n_total_cparams += 1;
     }
 
+  if (n_parameters == 0 && n_total_cparams == 0)
+    {
+      /* This is a simple object with no construct properties, and
+       * no properties are being set, so short circuit the parameter
+       * handling. This speeds up simple object construction.
+       */
+      oparams = NULL;
+      object = class->constructor (object_type, 0, NULL);
+      goto did_construction;
+    }
+
   /* collect parameters, sort into construction and normal ones */
   oparams = g_new (GObjectConstructParam, n_parameters);
   cparams = g_new (GObjectConstructParam, n_total_cparams);
@@ -1231,6 +1242,7 @@ g_object_newv (GType       object_type,
     g_value_unset (cvalues + n_cvalues);
   g_free (cvalues);
 
+ did_construction:
   /* adjust freeze_count according to g_object_init() and remaining properties */
   G_LOCK (construction_mutex);
   newly_constructed = slist_maybe_remove (&construction_objects, object);



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