Repository navigation
gh-161941: Freeze the encodings modules imported at startup - #161951
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>
Documentation build overview
|
|
Can you explain a bit better the import system changes? |
Background: a frozen package gets To allow
|
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.