Hi there,
Please find attached an horrible hack that cuts a second off my mutter
startup or so. It reduces the number of nbtk_stylable_get_style_id calls
from 235k to 12k and the same for nbtk_stylable_get_style_class calls.
For some obscure reason (and perhaps the real fix is here) - we call
each of these methods around 20 times each, back to back ;-) so the
cache helps rather a lot.
This reduces the cost of 'get_style_id' and 'get_style_class' from 20%+
to less than 1% of startup [ though there is a mismatch in those two
numbers locally ;-] Be great to get some testing / input from someone
who actually knows what is going on here ;-)
It is of course possible that we see a lot more pain here because we
don't turn off type-checking in gobject [ something sure to cause
'interesting' effects in the rest of the stack ;-], but hopefully it's a
win whatever.
HTH,
Michael.
--- boilerplate waiver ---
The attached patches are submitted under the terms here:
http://bugzilla.openedhand.com/waiver.html applied to whatsoever
product to which they apply, rather than to clutter:
--
[email protected] <><, Pseudo Engineer, itinerant idiot
Re-factor nbtk_style_node creation to share code.
Add style id and class cache - since (for reasons unknown)
we call these methods around 20 times each, back to back.
diff --git a/nbtk/nbtk-style.c b/nbtk/nbtk-style.c
index c917161..ec50de9 100644
--- a/nbtk/nbtk-style.c
+++ b/nbtk/nbtk-style.c
@@ -76,6 +76,8 @@ typedef struct {
ccss_node_t parent;
NbtkStylable *stylable;
NbtkStylableIface *iface;
+ const char *style_id;
+ const char *style_class;
} nbtk_style_node_t;
static ccss_function_t const * peek_css_functions (void);
@@ -405,9 +407,25 @@ nbtk_style_get_default (void)
/* functions for ccss */
static nbtk_style_node_t *
+style_node_new (ccss_node_class_t *node_class,
+ NbtkStylable *stylable,
+ NbtkStylableIface *iface)
+{
+ nbtk_style_node_t *node;
+
+ node = g_new0 (nbtk_style_node_t, 1);
+ ccss_node_init ((ccss_node_t*) node, node_class);
+ node->stylable = stylable;
+ node->iface = iface;
+ node->style_id = nbtk_stylable_get_style_id (stylable);
+ node->style_class = nbtk_stylable_get_style_class (stylable);
+
+ return node;
+}
+
+static nbtk_style_node_t *
get_container (nbtk_style_node_t *node)
{
- nbtk_style_node_t *container;
ClutterActor *parent;
g_return_val_if_fail (node, NULL);
@@ -421,18 +439,15 @@ get_container (nbtk_style_node_t *node)
if (!parent)
return NULL;
- container = g_new0 (nbtk_style_node_t, 1);
- ccss_node_init ((ccss_node_t*) container, peek_node_class ());
- container->iface = node->iface;
- container->stylable = NBTK_STYLABLE (parent);
-
- return container;
+ return style_node_new (peek_node_class (),
+ NBTK_STYLABLE (parent),
+ node->iface);
}
static const gchar*
get_style_id (nbtk_style_node_t *node)
{
- return nbtk_stylable_get_style_id (node->stylable);
+ return node->style_id;
}
static const gchar*
@@ -444,7 +459,7 @@ get_style_type (nbtk_style_node_t *node)
static const gchar*
get_style_class (nbtk_style_node_t *node)
{
- return nbtk_stylable_get_style_class (node->stylable);
+ return node->style_class;
}
static const gchar*
@@ -634,11 +649,7 @@ nbtk_style_get_property (NbtkStyle *style,
ccss_style_t *ccss_style;
nbtk_style_node_t *ccss_node;
- ccss_node = g_new0 (nbtk_style_node_t, 1);
- ccss_node_init ((ccss_node_t*) ccss_node, peek_node_class ());
- ccss_node->iface = iface;
- ccss_node->stylable = stylable;
-
+ ccss_node = style_node_new (peek_node_class (), stylable, iface);
ccss_style = ccss_stylesheet_query (priv->stylesheet,
(ccss_node_t *) ccss_node);
if (ccss_style)
@@ -707,10 +718,7 @@ nbtk_style_get_valist (NbtkStyle *style,
ccss_style_t *ccss_style;
nbtk_style_node_t *ccss_node;
- ccss_node = g_new0 (nbtk_style_node_t, 1);
- ccss_node_init ((ccss_node_t*) ccss_node, peek_node_class ());
- ccss_node->iface = iface;
- ccss_node->stylable = stylable;
+ ccss_node = style_node_new (peek_node_class (), stylable, iface);
ccss_style = ccss_stylesheet_query (priv->stylesheet,
(ccss_node_t *) ccss_node);
if (ccss_style)
_______________________________________________
Moblin dev Mailing List
[email protected]
To manage or unsubscribe from this mailing list visit:
https://lists.moblin.org/mailman/listinfo/dev or your user account on
http://moblin.org once logged in.
For more information on the Moblin Developer Mailing lists visit:
http://moblin.org/community/mailing-lists