Open
Description
Feature or enhancement
Proposal:
Following on from #109653, further improvements can be made to import times.
Links to previous discussion of this feature:
For example:
importlib.metadata
is often used for tasks that need to happen at import, e.g. to enumerate/load entry point plug-ins, so it might be worth seeing if we can cut down its own import time a bit more.
importlib.metadata
imports zipfile
at the top for a function that won't be called in the vast majority of cases. It also imports importlib.abc
, which in turn imports importlib.resources
, to subclass an ABC with a single, non-abstract method - I assume redefining the method in importlib.metadata
would be harmless. Some other less frequently-used imports which are only accessed once or twice, such as json
, could also be tucked away in their calling functions.
Linked PRs
- gh-118761: Improve import time of
pprint
#122725 - gh-118761: Speedup pathlib import by deferring shutil #123520
- gh-121423: Improve import time of
socket
by writingsocket.errorTab
as a constant and lazy import modules #121424 - gh-118761: Improve import time of
mimetypes
#126979 - gh-118761: improve import time for
pickle
#128732 - gh-118761: substitute
re
import inbase64.b16decode
for a more efficient alternative #128736 - gh-118761: improve import time for
secrets
#128738 - gh-118761: Improve import time for
csv
#128858 - gh-118761: Reduce import time of gettext.py by delaying re import #128898
- gh-118761: improve optparse import time by delaying textwrap import #128899
- gh-118761: Improve import time of
tomllib
#128907 - gh-118761: Improve import time for
pstats
andzipfile
by removing imports totyping
#128981 - gh-118761: Improve import time of
sqlite3
#129118 - gh-118761: Improve import time of
subprocess
#129427 - gh-118761: Always lazy import
warnings
inthreading
#129428 - [3.13] gh-118761: Improve import time of
subprocess
(GH-129427) #129447 - [3.12] gh-118761: Improve import time of
subprocess
(GH-129427) #129448