GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — Windows: avoid importing encodings._win_cp_codecs and time at startup · Issue #161510 · python/cpython Open Labels OS-windowsperformancePerformance or resource usagePerformance or resource usagestdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-lazy-importstype-featureA feature request or enhancementA feature request or enhancement DescriptionFeature or enhancementOn Windows,
From Moving both imports into the functions that use them (patch below) made
Both imports are unchanged on main (2781ffe). The change, against main: patchdiff --git a/Lib/encodings/__init__.py b/Lib/encodings/__init__.py index 04594ea..bbccb93 100644 --- a/Lib/encodings/__init__.py +++ b/Lib/encodings/__init__.py @@ -157,8 +157,6 @@ def search_function(encoding): codecs.register(search_function) if sys.platform == 'win32': - from ._win_cp_codecs import create_win32_code_page_codec - def win32_code_page_search_function(encoding): encoding = encoding.lower() if not encoding.startswith('cp'): @@ -173,6 +171,7 @@ if sys.platform == 'win32': except (OverflowError, OSError): return None + from ._win_cp_codecs import create_win32_code_page_codec return create_win32_code_page_codec(cp) codecs.register(win32_code_page_search_function) diff --git a/Lib/zipimport.py b/Lib/zipimport.py index 09a85f6..aae77df 100644 --- a/Lib/zipimport.py +++ b/Lib/zipimport.py @@ -16,7 +16,6 @@ import _frozen_importlib as _bootstrap # for _verbose_message import _imp # for check_hash_based_pycs import _io # for open import marshal # for loads -import time # for mktime __all__ = ['ZipImportError', 'zipimporter'] @@ -767,6 +766,8 @@ def _compile_source(pathname, source, module): # Convert the date/time values found in the Zip archive to a value # that's compatible with the time stamp stored in .pyc files. def _parse_dostime(d, t): + # Imported here: importing time at start-up costs a time zone lookup. + import time return time.mktime(( (d >> 9) + 1980, # bits 9..15: year (d >> 5) & 0xF, # bits 5..8: month I used GitHub Copilot (Claude Opus 5.5 model) to trace this, build and time the prototype, and draft this issue. The measurements were run on my machine. Has this already been discussed elsewhere?This is a minor feature, which does not need previous discussion elsewhere Links to previous discussion of this feature:No response Linked PRsActivity
MetadataMetadataAssigneesLabelsOS-windowsperformancePerformance or resource usagePerformance or resource usagestdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-lazy-importstype-featureA feature request or enhancementA feature request or enhancement ProjectsMilestoneRelationshipsDevelopmentIssue actions |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |