You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=<Date2020-06-17.21:36:12.127>created_at=<Date2020-06-17.13:58:21.130>labels= ['library', '3.10']
title='Reduce number of modules imported by runpy'updated_at=<Date2020-06-17.23:20:57.312>user='https://github.com/vstinner'
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%)
Activity
vstinner commentedon Jun 17, 2020
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:
Example with attached mod.py:
vstinner commentedon Jun 17, 2020
My local changes removed the following imports from runpy:
vstinner commentedon Jun 17, 2020
Oops sorry, that's with my local changes!
Currently, runpy imports not less than 37 modules:
vstinner commentedon Jun 17, 2020
See also bpo-40275: "test.support has way too many imports".
vstinner commentedon Jun 17, 2020
I created 3 PRs. I have a few more local branches to avoid types and itertools imports. I may create PRs for these ones as well.
vstinner commentedon Jun 17, 2020
New changeset 7824cc0 by Victor Stinner in branch 'master':
bpo-41006: collections imports lazily heap (GH-20940)
7824cc0
vstinner commentedon Jun 17, 2020
New changeset 98ce7b1 by Victor Stinner in branch 'master':
bpo-41006: pkgutil imports lazily re (GH-20939)
98ce7b1
vstinner commentedon Jun 17, 2020
New changeset 9e09849 by Victor Stinner in branch 'master':
bpo-41006: importlib.util no longer imports typing (GH-20938)
9e09849
vstinner commentedon Jun 17, 2020
I close the issue. Making more imports lazy doesn't bring much benefit.
--
With the 3 changes, runpy now imports 55 modules, instead of 70.
The startup time is 1.3x faster, 18 ms instead of 24 ms:
Mean +- std dev: [before] 23.7 ms +- 0.4 ms -> [after] 17.8 ms +- 0.6 ms: 1.33x faster (-25%)
--
Avoiding itertools and types doesn't bring much benefit:
Mean +- std dev: [after] 17.8 ms +- 0.6 ms -> [WIP] 17.2 ms +- 0.4 ms: 1.03x faster (-3%)
vstinner commentedon Jun 17, 2020
New changeset 4c18fc8 by Victor Stinner in branch 'master':
bpo-41006: Document the runpy optimization (GH-20953)
4c18fc8
vstinner commentedon Jun 17, 2020
New changeset 1bf7959 by Victor Stinner in branch 'master':
bpo-41006: Remove init_sys_streams() hack (GH-20954)
1bf7959
vstinner commentedon Jun 17, 2020
New changeset 2c2a4f3 by Victor Stinner in branch 'master':
bpo-41006: What's New: less => fewer modules (GH-20955)
2c2a4f3