[pygtk] some test on how to improve the load time of pygtk
Rafael Espíndola
rafael.espindola at gmail.com
Tue Jul 25 22:44:39 WST 2006
In order to test some ideas on how to improve the load time of pygtk I
have written a small module to play with. The module is just the spam
module with two copies of the system function.
the code of the tests can be found in
http://www.maemo.org.br/platform/rafael/pygtk
The v1 is just a canonical implementation. It has 11 relocations and 5
PLT entries.
In v2 the global table was replaced with one with relative addresses
to avoid relocation. At runtime the global address is computed. It has
5 relocations and 5 PLT entries. The BIG problem is that the relative
addresses are generated with inline assembly.
in v3 only _get_symbol is exported to python. An internal table is
used in _get_symbol. It has 15 relocations and 8 PLT entries
in v4 _get_symbol is implemented with a relative table. Inline
assembly is used. 9 relocations and 8 PLT entries.
in v5 _get_symbol is implemented with a if/else if/ chain. 9
relocations, 7 PLT entries. The code is a bit slower and bigger, but
this can be improved.
in v6 the dso is read to extract the addresses used in _get_symbol. 9
relocations, 8 PLT entries. Reading the dso is really a hack!
I think that the only viable implementation by now is v5. PyGtk
already has some code to support it, and I can give it a try.
I have started a thread in the gcc mailing list about implementing a
ld/as/gcc extention to make it easy to generate a global table with
relative addresses. But it will take some time to have a conclusion.
Another unrelated improvement that I have in mind is to try to reduce
the size of the generated code.
For example, _wrap_gtk_icon_set_copy can be implemented as
----------------------------------------------------------------------
static PyObject *
_wrap_gtk_icon_set_copy(PyObject *self)
{
return foo(self, gtk_icon_set_copy)
}
---------------------------------------------------------------------
where foo is
---------------------------------------------------------------------
static PyObject *
foo(PyObject *self, f_type *f)
{
GtkIconSet *ret;
ret = f(pyg_boxed_get(self, GtkIconSet));
/* pyg_boxed_new handles NULL checking */
return pyg_boxed_new(GTK_TYPE_ICON_SET, ret, FALSE, TRUE);
}
--------------------------------------------------------------------
There are other functions that can be implemented with "foo", so i
think that we will get a nice code reduction. And if we are going to
create PyCFunction_NewEx dynamically in _get_symbol, it might be
possible to not declare _wrap_gtk_icon_set_copy at all and store a
pointer to gtk_icon_set_copy in the self pointer.
Sorry for the long brain dump :-)
Best Regards,
Rafael
More information about the pygtk
mailing list