- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 33.3k
Closed
Labels
performancePerformance or resource usagePerformance or resource usagestdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-importlibtype-featureA feature request or enhancementA feature request or enhancement
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 socketby writingsocket.errorTabas 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 reimport inbase64.b16decodefor 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 pstatsandzipfileby 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 warningsinthreading#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
- gh-118761: Improve import time by lazy import of warnings#129765
- gh-118761: Improve import time by lazy import of traceback#129811
- gh-118761: Always lazy import reinlocale#129860
- gh-118761: Improve import time of dataclasses#129925
- gh-118761: Improve import time of cmdmodule #130056
- gh-118761: Revert "Improve import time of subprocess(GH-129427)" #130201
- [3.13] gh-118761: Revert "Improve import time of subprocess(GH-129427)" (GH-130201) #130204
- [3.12] gh-118761: Revert "Improve import time of subprocess(GH-129427)" (GH-130201) #130205
- gh-137855: Improve import time of sqlite3#131796
- gh-118761: Optimise import time for ast #131953
- gh-137855: Optimise import time for textwrap #131956
- gh-118761: Fix star-import of ast#132024
- gh-118761: Fix star-import of ast (alternative) #132025
- gh-118761: Improve import time of annotationlib#132028
- gh-118761: Use enum._simple_enumforannotationlib.Format#132031
- gh-118761: Cover the import time optimisations in What's New #132035
- gh-118761: Optimise import time for shlex#132036
- gh-118761: Optimise import time for string#132037
- gh-137855: email.quoprimimeremovingreimport #132046
- gh-118761: Defer import of functools in annotationlib #132059
- gh-118761: Lazily import annotationlib in typing #132060
- GH-118761: Expose more core interpreter types in _types#132103
- gh-118761: Add helper to ensure that lazy imports are actually lazy #132614
- gh-118761: Add test_lazy_import for more modules #133057
danielhollas, hugovk, cmaloney, Wulian233, holmanb and 2 moreEDM115
Metadata
Metadata
Assignees
Labels
performancePerformance or resource usagePerformance or resource usagestdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-importlibtype-featureA feature request or enhancementA feature request or enhancement