import cost in bzr

Andrew Bennetts andrew at canonical.com
Tue May 16 14:58:45 BST 2006


On Tue, May 16, 2006 at 04:09:31PM +0300, Alexander Belchenko wrote:
[...]
> 
> I also run second tester for each python file in bzrlib directory and
> got this results on somewhat old machine (Duron 750MHz, 384MB RAM):
> 

Here's your top 20:

from bzrlib import builtins	1.04199981689
from bzrlib import workingtree	1.01099991798
from bzrlib import commit	1.00100016594
from bzrlib import add	0.991999864578
from bzrlib import merge	0.990999937057
from bzrlib import reconcile	0.971999883652
from bzrlib import repository	0.961999893188
from bzrlib import fetch	0.960999965668
from bzrlib import branch	0.950999975204
from bzrlib import bzrdir	0.891999959946
from bzrlib import upgrade	0.891000032425
from bzrlib import lockdir	0.651000022888
from bzrlib import annotate	0.641000032425
from bzrlib import knit	0.470999956131
from bzrlib import info	0.460999965668
from bzrlib import xml5	0.450999975204
from bzrlib import diff	0.450999975204
from bzrlib import xml4	0.440999984741
from bzrlib import status	0.440999984741
from bzrlib import weave	0.430999994278
from bzrlib import conflicts	0.421000003815

Here's my top 20, generated with the following bash:

export TIMEFORMAT="real %Rs"
(for module in bzrlib/*.py ; do module=${module#bzrlib/} ; module=${module%.py} ; echo -n "$module: " ; time python -c "import bzrlib.$module" ; done) 2>&1 | sort -r -n -t . -k 2

add: real 0.242s
builtins: real 0.226s
merge: real 0.222s
commit: real 0.221s
fetch: real 0.213s
repository: real 0.211s
workingtree: real 0.202s
reconcile: real 0.195s
branch: real 0.193s
upgrade: real 0.182s
bzrdir: real 0.182s
lockdir: real 0.143s
annotate: real 0.138s
xml4: real 0.100s
knit: real 0.099s
weave: real 0.096s
status: real 0.096s
conflicts: real 0.096s
diff: real 0.094s
patch: real 0.093s

The order of these change a fair bit, but the same modules show up fairly
reliably, particularly those that take more than 150ms to import on my system.

This isn't an entirely useful analysis, though.  I think a more useful approach
would be to examine what modules are loaded by executing various bzr commands
that are expected to be cheap.  A basic way to do this is with "python -v".  A
more sophisticated method might be to make bzr install an import hook if a
BZR_TRACE_IMPORTS environment variable is set.  It could potentially report what
modules are imported, and how often.

Another useful tool might be modulefinder, e.g.:

    python -m modulefinder bzrlib/workingtree.py

-Andrew.





More information about the bazaar mailing list