Slow "import hippo" and other on web browser activity startup
Marco Pesenti Gritti
mpg at redhat.com
Mon Apr 9 21:10:36 EDT 2007
On Mon, 2007-04-09 at 18:53 -0400, William Cohen wrote:
> Hi all,
> I was taking a closer look at where the startup time was spent when starting the
> web browser activity. The profile from python profiler looks like the following:
> import pstats
> p = pstats.Stats('/tmp/pywebprof')
> Mon Apr 9 18:19:30 2007 /tmp/pywebprof
> 11141 function calls (11070 primitive calls) in 20.860 CPU seconds
> Ordered by: internal time
> List reduced from 802 to 10 due to restriction <10>
> ncalls tottime percall cumtime percall filename:lineno(function)
> 1 5.320 5.320 5.320 5.320 :0(browser_startup)
> 1 4.360 4.360 7.650 7.650 :0(main)
> 1 2.930 2.930 4.300 4.300
> 1 1.390 1.390 2.320 2.320 :0(present)
> 1 0.970 0.970 1.130 1.130
> 1 0.340 0.340 0.380 0.380 /usr/lib/python2.4/socket.py:43(?)
> 29 0.200 0.007 0.200 0.007 :0(lookup_icon)
> 12 0.150 0.012 0.310 0.026
> 24 0.130 0.005 0.130 0.005 :0(type_register)
> 327 0.130 0.000 0.130 0.000 :0(lower)
> According to the profile the "import hippo" is taking a couple of seconds. I
> tried it from an interactive python command line and it does seems to take a
> while (2 or 3 seconds). Why does the import take so long?
I think "import hippo" will also cause the bindings for gtk to be
loaded, which is known to take a while. It has been profiled in the past
and it has been blamed on the big number of symbols that needs to be
linked. See this blog entry:
I think the work the blog entry talks about has not been completed
because it would have required to change pygtk in incompatible ways.
There is also the fact that while importing gtk python tries to open a
huge number of files (most of them doesn't exist) to find the modules in
the python path. It's unclear how much this actually affect performance.
(Python 2.5 is smarter about it and should try to open a lot less files)
strace python -c "import hippo"
to get an idea of what is going on.
This is not specific to the web activity and it's the reason because
even an empty window activity takes several seconds to startup on the
> Where is the code for browser_startup,
This will startup mozilla. The code is in
sugar/browser/sugar-browser.cpp but it's not that interesting. It just
call a function to initialize mozilla.
Just the gtk event loop, I think.
> and present to be found?
It's just showing the gtk.Window. My guess is that this is slow because
it cause the GtkMozEmbed widget to be realized and that triggers some
more mozilla initilization code.
Hope it's useful, thanks for looking into this!
More information about the Devel