Re: Static class instances possible?



On Fri, 18 Feb 2005 14:28:53 -0500, Havoc Pennington <hp redhat com> wrote:
> On Fri, 2005-02-18 at 10:11 +0200, Tommi Komulainen wrote:
> > As I've understood it currently all glib class instances are
> > dynamically built the first time an instance is needed. On a resource
> > limited device this contributes to slow application startup and I was
> > wondering if it would be possible during compilation to somehow
> > pre-build some class instances and have them in static (const?)
> > memory?
> 
> It isn't possible with how gobject works, because the class_init() is
> called for each superclass from GObject down to your subclass, and this
> creates the inheritance (virtual functions in the superclass are filled
> in by the superclass's class_init()). There's no way to get this
> information statically.
> 
> I doubt this shows up much in GTK's startup time, though...

It does, surprisingly a lot actually.  Though I admit only creating an
empty window doesn't much reflect real-world use.  In any case,
g_type_class_ref(GtkWindow) takes something like 40% of the startup
time.  With the default theme the figures are roughly as follows:

gtk_init: 242ms
gtk_window_new: 448ms
  of which g_type_class_ref(GtkWindow): 291ms

Considering that the first widget an application is likely to create
is a window I thought it might be worthwhile to try to short-circuit
that particular case and make startup snappier.  Though you probably
wouldn't see the effects on the desktop that clearly.


-- 
Tommi Komulainen                                      tkomulai gmail com



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]