New submission from STINNER Victor <vstin...@python.org>:
Currently, the runpy module imports many modules. runpy is used by "python3 -m module". I propose to attempt to reduce the number of imports to reduce Python startup time. With my local changes, I reduce Python startup time from 24 ms to 18 ms: Mean +- std dev: [ref] 24.3 ms +- 0.2 ms -> [patch] 18.0 ms +- 0.3 ms: 1.35x faster (-26%) Timing measured by: ./python -m venv env python -m pyperf command -v -o patch.json -- env/bin/python -m empty Currently, runpy imports +21 modules: * ./python mod.py: Total 33 * ./python -m mod: Total 54 (+21) Example with attached mod.py: $ ./python -m mod ['__main__', '_abc', '_codecs', '_collections', '_collections_abc', '_frozen_importlib', '_frozen_importlib_external', '_functools', '_heapq', '_imp', '_io', '_locale', '_operator', '_signal', '_sitebuiltins', '_sre', '_stat', '_thread', '_warnings', '_weakref', '_weakrefset', 'abc', 'builtins', 'codecs', 'collections', 'collections.abc', 'contextlib', 'copyreg', 'encodings', 'encodings.aliases', 'encodings.ascii', 'encodings.latin_1', 'encodings.utf_8', 'enum', 'functools', 'genericpath', 'heapq', 'importlib', 'importlib._bootstrap', 'importlib._bootstrap_external', 'importlib.abc', 'importlib.machinery', 'importlib.util', 'io', 'itertools', 'keyword', 'marshal', 'operator', 'os', 'os.path', 'pkgutil', 'posix', 'posixpath', 're', 'reprlib', 'runpy', 'site', 'sre_compile', 'sre_constants', 'sre_parse', 'stat', 'sys', 'time', 'types', 'typing', 'typing.io', 'typing.re', 'warnings', 'weakref', 'zipimport'] Total 70 ---------- components: Library (Lib) files: mod.py messages: 371741 nosy: vstinner priority: normal severity: normal status: open title: Reduce number of modules imported by runpy versions: Python 3.10 Added file: https://bugs.python.org/file49240/mod.py _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue41006> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com