GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-161510: Lazily import time and encodings._win_cp_codecs at startup by azchohfi · Pull Request #161732 · python/cpython

Conversation

@azchohfi

@azchohfi azchohfi commented Nov 10, 2026 •
edited by bedevere-app Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

As discussed in the issue, this uses lazy imports for two modules. time in zipimport is only needed by _parse_dostime. create_win32_code_page_codec in encodings, on Windows only, is needed only for code pages without a codec module.

@aisk is right about time. Logging, subprocess, asyncio, the REPL (through _pyrepl.commands), pip and pytest all import it anyway, so that half only helps short commands like python -c one-liners and scripts that don't use those modules. _win_cp_codecs is different: it stayed unloaded in every case I tried, including the REPL, pip, pytest and asyncio, because it's only needed when a code page has no Python codec.

On Windows 11, python -c pass got about 1.7 ms faster (release build of main, 200 alternating runs).

I added a test for each with ensure_lazy_imports, and both fail without the change. zipimport is frozen, so its test checks that time isn't imported at startup. test_codecs, test_zipimport, test_zipimport_support, test_lazy_import, test_embed, test_frozen, test_time, test_sys and test_cmd_line pass on Windows and Linux.

AI disclosure: I used GitHub Copilot to help with testing and benchmarking.

  • Issue: Windows: avoid importing encodings._win_cp_codecs and time at startup #161510

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@azchohfi
pythongh-161510: Lazily import time and encodings._win_cp_codecs at s…
d4ce789
…tartup
@azchohfi
azchohfi requested review from FFY00, brettcannon, ericsnowcurrently, ncoghlan and warsaw as code owners November 10, 2026 05:30
@bedevere-app bedevere-app Bot added the type-feature A feature request or enhancement label Nov 10, 2026
@bedevere-app bedevere-app Bot mentioned this pull request Nov 10, 2026
Windows: avoid importing encodings._win_cp_codecs and time at startup #161510
Open
@bedevere-app bedevere-app Bot added the awaiting review label Nov 10, 2026
aisk
aisk approved these changes Nov 10, 2026
View reviewed changes
@bedevere-app bedevere-app Bot added awaiting core review and removed awaiting review labels Nov 10, 2026
StanFromIreland
StanFromIreland reviewed Nov 10, 2026
View reviewed changes
Comment thread Misc/NEWS.d/next/Library/2026-11-09-09-21-52.gh-issue-161510.r1ALA6.rst Outdated

@StanFromIreland StanFromIreland Nov 10, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are internal details that we shouldn't document.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@azchohfi azchohfi Nov 10, 2026

Copy link
Copy Markdown
Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, removed. Could you add the skip news label?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@azchohfi
Remove NEWS entry
557c928
@bedevere-app

bedevere-app Bot commented Nov 10, 2026

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@StanFromIreland StanFromIreland added the skip news label Nov 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@StanFromIreland StanFromIreland StanFromIreland left review comments
@aisk aisk aisk approved these changes
@brettcannon brettcannon Awaiting requested review from brettcannon brettcannon is a code owner
@ericsnowcurrently ericsnowcurrently Awaiting requested review from ericsnowcurrently ericsnowcurrently is a code owner
@ncoghlan ncoghlan Awaiting requested review from ncoghlan ncoghlan is a code owner
@warsaw warsaw Awaiting requested review from warsaw warsaw is a code owner
@FFY00 FFY00 Awaiting requested review from FFY00 FFY00 is a code owner

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

awaiting core review skip news type-feature A feature request or enhancement

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@azchohfi @aisk @StanFromIreland
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.
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.