[Python-Dev] Python startup time

Christian Heimes christian at python.org
Wed Oct 9 14:54:24 CEST 2013


Am 09.10.2013 14:39, schrieb Benjamin Peterson:
> There's also the increasing number of modules (Python or otherwise)
> that have to be loaded on startup.

I have gathered some stats:

Python 3.4:
>>> len(sys.modules)
56
>>> len(list(name for name in sys.modules
             if name not in sys.builtin_module_names))
36
>>> sorted(sys.modules)
['__main__', '_codecs', '_collections', '_frozen_importlib',
'_functools', '_heapq', '_imp', '_io', '_operator', '_sitebuiltins',
'_sre', '_stat', '_sysconfigdata', '_thread', '_warnings', '_weakref',
'_weakrefset', 'abc', 'atexit', 'builtins', 'codecs', 'collections',
'collections.abc', 'copyreg', 'encodings', 'encodings.aliases',
'encodings.latin_1', 'encodings.utf_8', 'errno', 'functools',
'genericpath', 'heapq', 'io', 'itertools', 'keyword', 'marshal',
'operator', 'os', 'os.path', 'posix', 'posixpath', 're', 'readline',
'reprlib', 'rlcompleter', 'signal', 'site', 'sre_compile',
'sre_constants', 'sre_parse', 'stat', 'sys', 'sysconfig', 'types',
'weakref', 'zipimport']

Python does quite alot of syscalls, too:

$ strace ./python -E -c '' 2>&1 | grep stat | wc -l
236
$ strace ./python -E -c '' 2>&1 | grep open | wc -l
53

Python 2.7 is a bit better:
>>> len(sys.modules)
41
>>> len(list(name for name in sys.modules
             if name not in sys.builtin_module_names))
29




More information about the Python-Dev mailing list