lazy loading override classes



Hi,

"from gi.repository import Gtk" naturally triggers the Gtk overrides
file to be imported, and the nature of Python is that this causes a
lot of work to be done. For example, for each class defined there, it
goes ahead and sets up the GObjectMeta, class hierarchies, MRO
calculations, etc.

The GTK overrides file is big and some apps will not even use any of
the hierarchies that are now being prepared. It would be nice if we
could do this lazily.

I am experimenting with a lazy loading approach where the class
definitions are placed in specially decorated functions. Python does
not "descend" into such functions at import time. This causes a 25%
improvement in "import Gtk" timing (which actually brings us down to
pygtk2 import speed).

The way to override a class in overrides is now:

@class_override('Widget')
def override_Widget():
    class Widget(Gtk.Widget)
        [...]

     return Widget

There is a new consideration if you want to access the overridden
Widget class from another point in the overrides file - you have to go
up to the DynamicModule instance to find it.

http://dev.laptop.org/~dsd/20130809/class_override.patch

I have ported Gtk and parts of GObject and GLib.

Before I continue with this and open a bug I would be interested in
any quick comments.

Specifically, should I be worried about breaking the API between
overrides and the core, or can I break it without worrying about
back-compat?

Right now it is backwards compatible but for cleanliness and
efficiency I would prefer to remove the old way after porting all
users.

Thanks
Daniel


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