python startup time

Gordon McMillan gmcm at hypernet.com
Mon Mar 20 02:57:24 CET 2000


Quinn Dunkan asks:

> Why does the python take so long to start up?  Is it because it loads so many
> modules?  And if that is the case, why is module loading slow?  

Partly.

There are 2 big factors. First is getpath.c, which attempts to 
ascertain as completely as possible what the proper sys.path 
is on your machine, and defends itself against sys admin-ish 
tricks, developers running from strange places, damaged 
OSes and other factors. It does a lot of hunting and pecking in 
the process. If you're willing to live with some simple rules, 
you can cut much of that out.

Imports can also be a problem. For each entry in sys.path, 
Python will first try for c extensions, then pure Python 
modules (which takes checking the .py against the .pyc / 
.pyo). On both my NT box and my Linux box, I've put the 
standard lib in a .pyz (an archive of compressed .pyc's) which 
is much, much faster. This is all straight out of the installer 
stuff on my starship pages (using Greg Stein's imputil module).


- Gordon




More information about the Python-list mailing list