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-156774: Speed up pdb startup with asyncio guard by brittanyrey · Pull Request #156775 · python/cpython

Conversation

@brittanyrey

@brittanyrey brittanyrey commented Sep 1, 2026 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

summary

  • Guard expensive asyncio import on if the current program is using asyncio at all.

perf

Broken out impact of lazy imports + asyncio guard
Without it, only the initial import really improves:

Benchmark asyncio guard
import pdb -28.8%
breakpoint() → continue -28.5%
python -m pdb script -26.0%
pdb post-mortem -24.6%
  • Issue: Optimize pdb with asyncio gating #156774

Sorry, something went wrong.

Uh oh!

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

All reactions
@brittanyrey
gh-999998: Speed up pdb startup with lazy imports
3c199f4
Defer the eight imports that are not already pulled in by pdb's
required-eager imports (cmd, bdb, code, typing and the guarded
_pyrepl.utils), and lift five unguarded function-level imports to
module-scope lazy imports.

Guard Pdb._get_asyncio_task() on 'asyncio' in sys.modules. It runs on every
interaction(), so without the guard the deferred asyncio import is paid back
immediately on the first breakpoint and the lazy import buys nothing for an
actual debugging session. If asyncio was never imported there cannot be a
running task, so returning None is equivalent.

The guarded imports (readline, rlcompleter, _pyrepl) stay function-level:
they sit in try/except ImportError blocks, and hoisting them would move the
failure outside the guard.

import pdb              -42.1%
breakpoint() -> cont    -41.1%
python -m pdb script    -33.4%
pdb post-mortem         -33.3%
@brittanyrey
brittanyrey requested a review from gaogaotiantian as a code owner September 1, 2026 13:52
@bedevere-app bedevere-app Bot mentioned this pull request Sep 1, 2026
Optimize pdb with asyncio gating #156774
Closed
@bedevere-app bedevere-app Bot added the awaiting review label Sep 1, 2026
@brittanyrey
pythongh-156774: Point pdb lazy-import NEWS entry at the filed issue
8d15fb1
@hugovk

hugovk commented Sep 1, 2026

Copy link
Copy Markdown
Member

See #156567 for the lazy imports, your review welcome!

I was planning on doing the asyncio guard as a followup :) Shall we reduce this PR to just that?

brittanyrey reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

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

@brittanyrey

brittanyrey commented Sep 1, 2026

Copy link
Copy Markdown
Contributor Author

Sorry about that! I did a peek over the lazy imports label & missed your issue!

I'm glad to scope this down to just the asyncio gated change.

All reactions

Sorry, something went wrong.

Uh oh!

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

@brittanyrey brittanyrey changed the title gh-156774: Speed up pdb startup with lazy imports + asyncio guard gh-156774: Speed up pdb startup with asyncio guard Sep 1, 2026
@brittanyrey
pythongh-156774: Scope pdb change down to the asyncio import only
89fccc3
Drop the other lazy imports and the lifted function-level imports, leaving
just the asyncio deferral and the _get_asyncio_task() guard. Those two carry
most of the win and keep the diff to five lines.

import pdb              -28.8% (was -42.1% with the full set)
breakpoint() -> cont    -28.5%
python -m pdb script    -26.0%
pdb post-mortem         -24.6%
@brittanyrey

brittanyrey commented Sep 1, 2026

Copy link
Copy Markdown
Contributor Author

PR + issue are fully rescoped @hugovk

hugovk reacted with rocket emoji
All reactions
  • 🚀 1 reaction

Sorry, something went wrong.

Uh oh!

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

johnslavik
johnslavik approved these changes Sep 1, 2026
View reviewed changes
@bedevere-app bedevere-app Bot added awaiting core review and removed awaiting review labels Sep 1, 2026
hugovk
hugovk approved these changes Sep 2, 2026
View reviewed changes

@hugovk hugovk left a comment

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.

Thanks!

Sorry, something went wrong.

Uh oh!

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

brittanyrey reacted with heart emoji
All reactions
  • ❤️ 1 reaction
Comment thread Lib/pdb.py Resolved

Uh oh!

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

@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting core review labels Sep 2, 2026
maurycy
maurycy reviewed Sep 2, 2026
View reviewed changes
Comment thread Misc/NEWS.d/next/Library/2026-08-31-11-40-00.gh-issue-156774.Pd8Lz1.rst Resolved

Uh oh!

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

@brittanyrey
Address comments
5ad79b2
@hugovk
hugovk merged commit 024b6bc into python:main Sep 8, 2026
51 checks passed

Uh oh!

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

@bedevere-app bedevere-app Bot removed the awaiting merge label Sep 8, 2026
@brittanyrey
brittanyrey deleted the b-perf-pdb-lazy-imports branch September 8, 2026 15:53
maurycy added a commit to maurycy/cpython that referenced this pull request Sep 10, 2026
@maurycy
Merge branch 'main' into tachyon-native-callable
e028ff5
* main: (158 commits)
  pythongh-156924: Try reifying lazy imports in `ForwarRef.evaluate()` (python#156940)
  pythongh-156233: Fix typos and code snippet errors in the docs (python#156475)
  pythongh-156837: Refer to yield expressions in generator function definitions (pythonGH-156863)
  pythongh-155292: Skip updating unicodedata with mismatched interpreter (pythonGH-157066)
  pythongh-157170: Document the scope of global curses settings (pythonGH-157207)
  pythongh-155966: Correct handling of `math.tanpi` poles (python#155980)
  pythongh-157170: Restore use_env() after test_use_prescr_screen in test_curses (pythonGH-157171)
  pythongh-156910: fix deadlock in type_set_abstractmethods under free-threading (python#156948)
  pythongh-155648: Write the empty and placeholder IDLE tests (python#156260)
  pythongh-153569: centralize formatted-string state and source spans (python#156484)
  pythongh-157137: Mark the PEP 820 soft deprecations as 3.15, not `next` (python#157138)
  pythongh-152433: Use regular LoadLibrary in UWP for Windows system libs (pythonGH-156972)
  pythongh-121617: Fix Py_CLEAR() memcpy in C++: replace NULL with _Py_NULL (python#157188)
  pythongh-157135: Fix documentation errors in the `math.atan{2}pi` functions (python#157136)
  pythongh-121617: Fix Py_CLEAR() in C++: replace NULL with _Py_NULL (python#157067)
  pythongh-156774: Speed up pdb startup with asyncio guard (python#156775)
  pythongh-156109: Allow static, non-framework iOS builds (python#156110)
  pythongh-156780: Emscripten: add missing EM_JS_DEPS (python#156798)
  pythongh-152936: Make privileged functions available on Android (python#152977)
  pythongh-123018: Keep the libedit history file header when truncating (pythonGH-157165)
  ...
clin1234 pushed a commit to clin1234/cpython that referenced this pull request Sep 12, 2026
@brittanyrey @clin1234
pythongh-156774: Speed up pdb startup with asyncio guard (python#156775)
72e3dff
johnslavik pushed a commit to johnslavik/cpython that referenced this pull request Sep 14, 2026
@brittanyrey @johnslavik
pythongh-156774: Speed up pdb startup with asyncio guard (python#156775)
ec0299c
@pablogsal pablogsal mentioned this pull request Oct 9, 2026
Request for Python triage membership: Brittany Reynoso python/core-workflow#609
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@hugovk hugovk hugovk approved these changes
@johnslavik johnslavik johnslavik approved these changes
@gaogaotiantian gaogaotiantian Awaiting requested review from gaogaotiantian gaogaotiantian is a code owner
+1 more reviewer
@maurycy maurycy maurycy left review comments
Reviewers whose approvals may not affect merge requirements

Uh oh!

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

Assignees

No one assigned

Labels

None yet

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.

4 participants

@brittanyrey @hugovk @maurycy @johnslavik
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.