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 564016 - add nsprefix to gir and typelib
add nsprefix to gir and typelib
Status: RESOLVED FIXED
Product: gobject-introspection
Classification: Platform
Component: general
unspecified
Other Linux
: Normal normal
: ---
Assigned To: gobject-introspection Maintainer(s)
gobject-introspection Maintainer(s)
Depends on:
Blocks:
 
 
Reported: 2008-12-10 17:50 UTC by Colin Walters
Modified: 2015-02-07 16:45 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Bug 564016 - Add c:prefix to .gir (8.17 KB, patch)
2009-02-12 22:41 UTC, Colin Walters
none Details | Review
Bug 564016 - Include c:prefix in typelib, use it to optimize find_by_gtype (14.35 KB, patch)
2009-02-12 23:44 UTC, Colin Walters
accepted-commit_now Details | Review
Bug 564016 - Add c:prefix to .gir (8.44 KB, patch)
2009-03-16 21:07 UTC, Colin Walters
none Details | Review
Bug 564016 - Include c:prefix in typelib, use it to optimize find_by_gtype (15.37 KB, patch)
2009-03-16 21:08 UTC, Colin Walters
none Details | Review

Description Colin Walters 2008-12-10 17:50:05 UTC
We could speed up _find_by_gtype quite a lot if we included the "nsprefix" inside the typelib.  In a lot of cases this would mean only looking in one typelib instead of all of them.
Comment 1 Colin Walters 2008-12-10 17:52:24 UTC
The main case where you'd have to look in multiple typelibs is looking up "GSomething" - could be in GObject, or Gio.  Still though, probably a large win.
Comment 2 Johan (not receiving bugmail) Dahlin 2008-12-10 18:01:58 UTC
Alternatively, we could have a global cache with entries like this;

With a typename -> fully qualified name, eg:

  GtkButton -> entry(typelib name, [typelib + offset])

And when loading a typelib we'd populate that cache with all known gtype names.

insert_typelib would be this:

- g_hash_table_insert(typelib_name, typelib)
- for each gtype
  - g_hash_table_insert(type_names, [type_name + offset])

find_by_gtype would be this:

- g_type_name(gtype) -> type_name
- g_hash_table_lookup(type_name) -> qualified name
- split qualified name -> [typelib + offset]
- g_hash_table_lookup(typelib name)
- create & return GIBaseInfo

Would that work?
Comment 3 Colin Walters 2008-12-10 18:13:12 UTC
That would mean a large chunk of writable memory for each process.  The current cache is proportional to the number of GTypes seen by a program, whereas your suggestion is proportional to all GTypes.
Comment 4 Johan (not receiving bugmail) Dahlin 2008-12-10 19:14:22 UTC
Right. 
We'd probably need some numbers here to make a qualified decision. If the total number of GTypes available in a program is less than say 200, it would probably make sense. Dedicating say 4kB writable memory per process for this kind of lookup optimizations is quite reasonable.
Comment 5 Colin Walters 2009-02-12 22:41:59 UTC
Created attachment 128599 [details] [review]
Bug 564016 - Add c:prefix to .gir

This has a few use cases; the main one in mind right now is that
when we place this in the .typelib as well, we can use it to optimize
lookups based on GType names, by skipping entirely typelibs whose
c:prefix is not a prefix of the target type lookup.
Comment 6 Colin Walters 2009-02-12 23:44:18 UTC
Created attachment 128604 [details] [review]
Bug 564016 - Include c:prefix in typelib, use it to optimize find_by_gtype

Parse the c:prefix from the .gir, include it in the header.  Armed with this
information, we can now optimize lookups of GTypes because we
have the requirement that GTypes must start with the c:prefix.
Comment 7 Colin Walters 2009-02-12 23:46:31 UTC
Other reasons to include the c:prefix in the .gir is that it would allow us to eliminate the c:type from pretty much everything, because we know that c:prefix + giname == c:type.
Comment 8 Johan (not receiving bugmail) Dahlin 2009-03-15 15:00:32 UTC
Comment on attachment 128604 [details] [review]
Bug 564016 - Include c:prefix in typelib, use it to optimize find_by_gtype

Looks good
Comment 9 Colin Walters 2009-03-16 21:07:22 UTC
Created attachment 130784 [details] [review]
Bug 564016 - Add c:prefix to .gir

This has a few use cases; the main one in mind right now is that
when we place this in the .typelib as well, we can use it to optimize
lookups based on GType names, by skipping entirely typelibs whose
c:prefix is not a prefix of the target type lookup.
Comment 10 Colin Walters 2009-03-16 21:08:28 UTC
Created attachment 130785 [details] [review]
Bug 564016 - Include c:prefix in typelib, use it to optimize find_by_gtype

Parse the c:prefix from the .gir, include it in the header.  Armed with this
information, we can now optimize lookups of GTypes because we
have the requirement that GTypes must start with the c:prefix.
Comment 11 Colin Walters 2009-03-16 21:10:13 UTC
Ok, these patches work well except they break the gjs test suite.  The reason for this is that the tests/everything uses the namespace "Everything", but in fact everything inside there is prefixed with "Test".

I'm inclined to say we should fix the everything library; a test library we ship should conform to good GObject conventions.  Opinions?
Comment 12 Johan (not receiving bugmail) Dahlin 2009-03-16 21:10:54 UTC
Yes, everything should be fixed.
Comment 13 Colin Walters 2009-03-17 20:31:21 UTC
I had a simpler fix (and what we need to do anyways for the Clutter/Cogl case), is that we should fall back to searching all typelibs if the nsprefix lookup fails.
Comment 14 André Klapper 2015-02-07 16:45:09 UTC
[Mass-moving gobject-introspection tickets to its own Bugzilla product - see bug 708029. Mass-filter your bugmail for this message: introspection20150207 ]