Title: [233071] trunk/Source/WTF
Revision
233071
Author
[email protected]
Date
2018-06-21 23:41:10 -0700 (Thu, 21 Jun 2018)

Log Message

[GLIB] improve get_type() fast path in WEBKIT_DEFINE_TYPE
https://bugs.webkit.org/show_bug.cgi?id=186885

Reviewed by Anders Carlsson.

This is a backport of glib commit
https://gitlab.gnome.org/GNOME/glib/commit/e924f777369710221c3e0a9d7bf40392a27d1fa4

"The -fstack-protector-strong used in many distributions by default has a
rather drastic slowdown of the fast path in generated _get_type()
functions using G_DEFINE_* macros. The amount can vary by architecture,
GCC version, and compiler flags.

To work around this, and ensure a higher probability that our fast-path
will match what we had previously, we need to break out the slow-path
(registering the type) into a secondary function that is not a candidate
for inlining.

This ensures that the common case (type registered, return the GType id)
is the hot path and handled in the prologue of the generated assembly even
when -fstack-protector-strong is enabled."

* wtf/glib/WTFGType.h:

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (233070 => 233071)


--- trunk/Source/WTF/ChangeLog	2018-06-22 03:01:52 UTC (rev 233070)
+++ trunk/Source/WTF/ChangeLog	2018-06-22 06:41:10 UTC (rev 233071)
@@ -1,3 +1,29 @@
+2018-06-21  Carlos Garcia Campos  <[email protected]>
+
+        [GLIB] improve get_type() fast path in WEBKIT_DEFINE_TYPE
+        https://bugs.webkit.org/show_bug.cgi?id=186885
+
+        Reviewed by Anders Carlsson.
+
+        This is a backport of glib commit
+        https://gitlab.gnome.org/GNOME/glib/commit/e924f777369710221c3e0a9d7bf40392a27d1fa4
+
+        "The -fstack-protector-strong used in many distributions by default has a
+        rather drastic slowdown of the fast path in generated _get_type()
+        functions using G_DEFINE_* macros. The amount can vary by architecture,
+        GCC version, and compiler flags.
+
+        To work around this, and ensure a higher probability that our fast-path
+        will match what we had previously, we need to break out the slow-path
+        (registering the type) into a secondary function that is not a candidate
+        for inlining.
+
+        This ensures that the common case (type registered, return the GType id)
+        is the hot path and handled in the prologue of the generated assembly even
+        when -fstack-protector-strong is enabled."
+
+        * wtf/glib/WTFGType.h:
+
 2018-06-20  Yusuke Suzuki  <[email protected]>
 
         [GTK][WPE][Nicosia] Add name for Nicosia Painting Threads

Modified: trunk/Source/WTF/wtf/glib/WTFGType.h (233070 => 233071)


--- trunk/Source/WTF/wtf/glib/WTFGType.h	2018-06-22 03:01:52 UTC (rev 233070)
+++ trunk/Source/WTF/wtf/glib/WTFGType.h	2018-06-22 06:41:10 UTC (rev 233071)
@@ -20,6 +20,7 @@
 #pragma once
 
 #include <glib.h>
+#include <wtf/Compiler.h>
 
 #define WEBKIT_PARAM_READABLE (static_cast<GParamFlags>(G_PARAM_READABLE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB))
 #define WEBKIT_PARAM_WRITABLE (static_cast<GParamFlags>(G_PARAM_WRITABLE | G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB))
@@ -46,6 +47,7 @@
 #define _WEBKIT_DEFINE_TYPE_EXTENDED_BEGIN(TypeName, type_name, TYPE_PARENT, flags) \
 \
 static void type_name##_class_init(TypeName##Class* klass); \
+static GType type_name##_get_type_once(void); \
 static gpointer type_name##_parent_class = 0; \
 static void type_name##_finalize(GObject* object) \
 { \
@@ -68,23 +70,30 @@
     TypeName##Private* priv = G_TYPE_INSTANCE_GET_PRIVATE(self, type_name##_get_type(), TypeName##Private); \
     self->priv = priv; \
     new (priv) TypeName##Private(); \
-}\
+} \
+\
 GType type_name##_get_type(void) \
 { \
     static volatile gsize g_define_type_id__volatile = 0; \
     if (g_once_init_enter(&g_define_type_id__volatile)) { \
-        GType g_define_type_id = \
-            g_type_register_static_simple( \
-                TYPE_PARENT, \
-                g_intern_static_string(#TypeName), \
-                sizeof(TypeName##Class), \
-                (GClassInitFunc)type_name##_class_intern_init, \
-                sizeof(TypeName), \
-                (GInstanceInitFunc)type_name##_init, \
-                (GTypeFlags)flags); \
-        // Custom code follows.
-#define _WEBKIT_DEFINE_TYPE_EXTENDED_END() \
+        GType g_define_type_id = type_name##_get_type_once(); \
         g_once_init_leave(&g_define_type_id__volatile, g_define_type_id); \
     } \
     return g_define_type_id__volatile; \
-} // Closes type_name##_get_type().
+} /* Closes type_name##_get_type(). */ \
+\
+NEVER_INLINE static GType type_name##_get_type_once(void) \
+{ \
+    GType g_define_type_id =  \
+        g_type_register_static_simple( \
+            TYPE_PARENT, \
+            g_intern_static_string(#TypeName), \
+            sizeof(TypeName##Class), \
+            (GClassInitFunc)(void (*)(void))type_name##_class_intern_init, \
+            sizeof(TypeName), \
+            (GInstanceInitFunc)(void (*)(void))type_name##_init, \
+            (GTypeFlags)flags); \
+    /* Custom code follows. */
+#define _WEBKIT_DEFINE_TYPE_EXTENDED_END() \
+    return g_define_type_id; \
+} /* Closes type_name##_get_type_once() */
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to