Suggestions for speeding up Python interpreter startup

Matt Mackall mpm at selenic.com
Mon Oct 14 17:35:37 CDT 2013


On Sat, 2013-10-12 at 10:31 -0600, Eric Snow wrote:
> Considering that Mercurial has probably put some thought into Python's
> startup time, do you have any recommendations on specific improvements
> that could be made in the Python interpreter/stdlib regarding startup
> time (and perhaps memory usage)?

We have a demand loader. It makes startup ~3x faster. It also breaks the
following standard Python paradigm, so we have to blacklist several
standard modules:

try:
  import x
except ImportError:
  # import fails

A substantial fraction of startup time is spent searching for modules
exhaustively in the path. Huge paths of the sort that eggs users often
get are a disaster here.

>   There's some momentum on the topic
> on python-dev right now (default/3.4-only, sorry).  Thanks!

Start here:

$ time python2.7 -c 'print("hello world")'
hello world

real	0m0.012s

$ time python3.3 -c 'print("hello world")'
hello world

real	0m0.023s

$ time perl -e 'print "hello world\n"'
hello world

real	0m0.003s

$ time ruby -e 'print "hello world\n"'
hello world

real	0m0.004s

-- 
Mathematics is the supreme nostalgia of our time.




More information about the Mercurial-devel mailing list