[New-bugs-announce] [issue41006] Reduce number of modules imported by runpy

STINNER Victor report at bugs.python.org
Wed Jun 17 09:58:21 EDT 2020

New submission from STINNER Victor <vstinner at 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
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 <report at bugs.python.org>

More information about the New-bugs-announce mailing list