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 337058 - avoid relocations and save space when registering types
avoid relocations and save space when registering types
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: gobject
unspecified
Other Linux
: Normal normal
: ---
Assigned To: Tim Janik
gtkdev
Depends on:
Blocks:
 
 
Reported: 2006-04-03 17:50 UTC by Matthias Clasen
Modified: 2006-05-31 00:39 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
patch (3.35 KB, patch)
2006-04-03 17:52 UTC, Matthias Clasen
none Details | Review

Description Matthias Clasen 2006-04-03 17:50:32 UTC
The static const GTypeInfo structs used
for g_type_register_static cause quite a few relocations, and also, in
90% of the cases, most of the structs is always the same. The cost of
relocations can in most cases alleviated by prelink (though
LD_DEBUG=statistics shows me that prelink is not as reliable as one
might hope, at least on ix86. Jakub tells me this is due to the kernel
mapping the vDSO in an area that conflicts with prelinked libraries...).

Here is a proposal to avoid the use of a static const struct (see the
attached patch):

GType
g_type_register_static_simple (GType             parent_type,
                               const gchar      *type_name,
                               guint16           class_size,
                               GClassInitFunc    class_init,
                               guint16           instance_size,
                               GInstanceInitFunc instance_init,
                               GTypeFlags        flags);


The current trivial implementation fills a GTypeInfo struct on the
stack, but it should be possible to avoid the use of a struct
altogether. When doing this conversion for a single type in GTK+,
I see .text grow by 16 bytes, while .data shrinks by 62, so it
should be an overall win.
Comment 1 Matthias Clasen 2006-04-03 17:52:13 UTC
Created attachment 62680 [details] [review]
patch
Comment 2 Behdad Esfahbod 2006-04-04 21:25:02 UTC
Why not accepting all the fields (base_init, base_finalize, etc) too?  So everybody uses the new function?
Comment 3 Tim Janik 2006-05-31 00:39:48 UTC
applied to CVS:

2006-04-21  Matthias Clasen  <mclasen@redhat.com>

        * gobject.symbols:
        * gtype.[hc]: Add a g_type_register_static_simple
        variant of g_type_register_static that does not take 
        a relocation-causing GTypeInfo struct, and use it 
        in G_DEFINE_TYPE.