[Python-Dev] 2.3 startup speed?
Thomas Heller
theller@python.net
Fri, 11 Jul 2003 17:20:19 +0200
Jeremy Hylton <jeremy@zope.com> writes:
> On Fri, 2003-07-11 at 10:16, Fred L. Drake, Jr. wrote:
>> Perhaps, but... those imports only happen if it already looks like
>> you're running from a build directory, so they don't impact the
>> imports for an installed Python.
>
> You are so true. I just did fresh installs of 2.2.3 and 2.3 to see what
> happens when I run from an install Python.
>
> A nice minimal set of imports for 2.2.3:
>
> import site
> import os
> import posix
> import posixpath
> import stat
> import UserDict
> import copy_reg
> import types
> import __future__
>
> There are a lot more for 2.3 (and each one costs more).
>
> import zipimport
> import site
> import os
> import posix
> import posixpath
> import stat
> import UserDict
> import copy_reg
> import types
> import warnings
> import linecache
> import re
> import sre
> import sre_compile
> import _sre
> import sre_constants
> import sre_parse
> import string
> import encodings
> import codecs
> import _codecs
> import encodings.aliases
> import encodings.iso8859_15
>
> We can blame the extra imports on three new features.
>
> The zip import feature requires the zipimport module.
>
> The warnings feature requires warnings, linecache, and re, where re is
> costly -- seven imports in total. The top-level "import re" was removed
> from warnings.py, but it doesn't make any difference. The routine that
> *uses* the re module is called from the top-level of the warnings
> module.
>
> The default file system encoding feature requires the encodings and
> codecs packages to be loaded. That's another five imports.
>
> Anyone want to drop warnings and encodings? <0.9 wink>
>
Sure. There's another problem with these imports happening *very* early,
it breaks py2exe, and maybe also McMillan installer because these
imports happen *before* the import hook is installed.
Thomas