Repository navigation
gh-161941: Freeze the encodings modules imported at startup - #161951
Open
eendebakpt wants to merge 1 commit into
Open
eendebakpt wants to merge 1 commit into
eendebakpt wants to merge 1 commit into
Conversation
Freeze encodings, encodings.aliases, encodings.utf_8 and the platform codec modules again. They were unfrozen because a partially frozen package broke the import of its non-frozen submodules with a zipped standard library: FrozenImporter set the package's __path__ to the package directory in sys._stdlib_dir, which does not exist in that layout (sys._stdlib_dir is still set, to a missing directory), so encodings.oem and friends could not be found. FrozenImporter now checks that the directory exists. If it does not, the location of a standard library package is looked up on sys.path with PathFinder, so its non-frozen submodules are found wherever the standard library is, including inside a zip file. Frozen packages outside the standard library are not affected. Importing encodings from disk was the single largest item of interpreter startup on Windows: it needs the sys.path directory listings and four .pyc files before the first codec lookup. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
eendebakpt
requested review from
AA-Turner,
FFY00,
brettcannon,
emmatyping,
ericsnowcurrently,
erlend-aasland,
itamaro,
ncoghlan and
warsaw
as code owners
November 13, 2026 19:28
Documentation build overview
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Freeze
encodings,encodings.aliases,encodings.utf_8and the platform codec modules again.FrozenImporternow checks that the directory exists. If it does not, the location of a standard library package is looked up on sys.path with PathFinder, so its non-frozen submodules are found wherever the standard library is, including inside a zip file. Frozen packages outside the standard library are not affected. Importing encodings from disk was a large part of interpreter startup on Windows.Benchmark on the issue.