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 689847 - Add fast repeated typename -> GType resolver
Add fast repeated typename -> GType resolver
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: gobject
unspecified
Other Linux
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2012-12-07 15:05 UTC by Alexander Larsson
Modified: 2012-12-10 11:58 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Add GTypeReference for fast repeated name -> type lookups (8.89 KB, patch)
2012-12-07 15:05 UTC, Alexander Larsson
rejected Details | Review
css: Use GTypeReference to speed up name matching (7.26 KB, patch)
2012-12-07 15:10 UTC, Alexander Larsson
none Details | Review
css: Speed up name matching (9.23 KB, patch)
2012-12-07 16:38 UTC, Alexander Larsson
committed Details | Review
Add g_type_get_type_registration_serial() (3.57 KB, patch)
2012-12-07 16:41 UTC, Alexander Larsson
committed Details | Review

Description Alexander Larsson 2012-12-07 15:05:33 UTC
This is needed for the Gtk+ css matching system that lets you match against typenames.
Comment 1 Alexander Larsson 2012-12-07 15:05:58 UTC
Created attachment 230972 [details] [review]
Add GTypeReference for fast repeated name -> type lookups

The Gtk+ themeing system suports matching by type name, and it turns
out that repeatedly calling g_type_from_name() is pretty slow. But,
we can't pre-convert to a GType because a lot of the types in use
are not yet registred, but may be registred later.

So, we introduce an object that represents a name->gtype mapping, which
can be instantiated even for currently non-registred types, which will
handle the case of a type later being registred. Using this made my
EggListBox test case 6% faster going to/from backdrop mode.
Comment 2 Alexander Larsson 2012-12-07 15:10:26 UTC
Created attachment 230973 [details] [review]
css: Use GTypeReference to speed up name matching
Comment 3 Alexander Larsson 2012-12-07 16:38:49 UTC
Created attachment 230983 [details] [review]
css: Speed up name matching

We use the new g_type_get_type_registration_serial() so that we can
cache and properly invalidate the result of g_type_from_name().
Comment 4 Alexander Larsson 2012-12-07 16:41:34 UTC
Created attachment 230984 [details] [review]
Add g_type_get_type_registration_serial()

This lets you cache type lookup information and then know when
the cache information is out of date. In particular, we want this
in order to be able to cache g_type_from_name() lookups in the Gtk+
theme machinery.
Comment 5 Allison Karlitskaya (desrt) 2012-12-07 17:49:48 UTC
Review of attachment 230972 [details] [review]:

As discussed on IRC, this is just too evil...
Comment 6 Allison Karlitskaya (desrt) 2012-12-07 17:51:40 UTC
Review of attachment 230984 [details] [review]:

I'm happy with this approach.

Please only commit this at the same time as the Gtk patch (to make sure it's really what you need).
Comment 7 Matthias Clasen 2012-12-07 21:03:50 UTC
Review of attachment 230983 [details] [review]:

::: gtk/gtkcssselector.c
@@ +551,3 @@
+
+  return ref;
+}

How big does this table get ?

@@ +575,3 @@
+	ref->type = g_type_from_name (ref->name);
+    }
+}

Instead of doing this full loop over the hash table, you could do the recheck at lookup time, if you stored the serial with the ref:

ref = g_hash_table_lookup (name)
if (ref) {
  if (ref->type == G_TYPE_INVALID) {
    serial = g_type_get_registration_serial();
     if (ref->serial != serial) {
     ref->type = g_type_from_name (ref->name);
     ref->serial = serial;     
  }
  return ref;
}

Maybe not worth it...
Comment 8 Matthias Clasen 2012-12-07 21:03:59 UTC
Review of attachment 230984 [details] [review]:

::: gobject/gtype.c
@@ +398,3 @@
+ * g_type_get_type_registration_serial:
+ *
+ * Returns an opaque serial number that represents the state of the set of registred

registered, not registred
Comment 9 Alexander Larsson 2012-12-10 08:57:14 UTC
Review of attachment 230983 [details] [review]:

::: gtk/gtkcssselector.c
@@ +551,3 @@
+
+  return ref;
+}

I'll check

@@ +575,3 @@
+	ref->type = g_type_from_name (ref->name);
+    }
+}

Well, this slows down the fast path with multiple checks per lookup for a very uncommon case (got new types). Additionally it needs to store the serial in more places, and, most css typechecks has the typename at the rightmost so will be at the topmost of the tree and will thus be checked every time anyway, so we do as many checks anyway.
Comment 10 Alexander Larsson 2012-12-10 11:52:54 UTC
With current adwaita the table is 69 entries. i.e. 1104 bytes on 64bit and 552 bytes on 32bit. Thats assuming no malloc overhead though, so i'm changing this to use GSlice which should let us basically reach that (the struct size is the same as the GSList one, so we'll have other things of this size anyway).
Comment 11 Alexander Larsson 2012-12-10 11:56:13 UTC
Comment on attachment 230984 [details] [review]
Add g_type_get_type_registration_serial()

Attachment 230984 [details] pushed as e218b96 - Add g_type_get_type_registration_serial()
Comment 12 Alexander Larsson 2012-12-10 11:58:21 UTC
Attachment 230983 [details] pushed as a1ee2b7 - css: Speed up name matching