GNOME Bugzilla – Bug 337058
avoid relocations and save space when registering types
Last modified: 2006-05-31 00:39:48 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.
Created attachment 62680 [details] [review] patch
Why not accepting all the fields (base_init, base_finalize, etc) too? So everybody uses the new function?
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.