There have been a few complaints that it takes too long time to start up python programs, especially the ones which has been written to use GTK and other GNOME libraries.
Yesterday I wrote a program called python-launcher, inspired by maemo-launcher which is a way to reduce start up time and memory usage used by python processes.
The trick works in the following way:
When the system is started, a daemon is run which imports all the modules which we want to cache. The normal launcher (/usr/bin/python) is replaced by a small client which communicates with the header and tells it to fork a new process and then execute the python script.
The gtk module is already imported in the parent process so there’s no need to re-import it for each client (eg, application) that is going to use it.
The “import gtk” statement is now instantaneous, but there’s a small hidden cost of creating a new GdkDisplay and associating a cached GdkSettings inside the deamon itself before the application is executed.
Especially the OLPC suffers due to excessive start-up costs.
I got the following numbers:
importing gtk normally: 1000ms importing gtk with help if the launcher: less than 1 ms hidden cost in the daemon for each child: around ~60ms
I looked quickly at the smap script written by Ben Maurer and it appears that the added memory cost of using a deamon is already saved when launching the second process using gtk.
Update: Hi Planet OLPC! Thanks Ivan.