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-91048: Refactor and optimize remote debugging module by pablogsal · Pull Request #134652 · python/cpython

Conversation

@pablogsal

@pablogsal pablogsal commented May 25, 2025 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Member

Completely refactor Modules/_remote_debugging_module.c with improved code organization, replacing scattered reference counting and error handling with centralized goto error paths. This cleanup improves maintainability and reduces code duplication throughout the module while preserving the same external API.

Implement memory page caching optimization in Python/remote_debug.h to avoid repeated reads of the same memory regions during debugging operations. The cache stores previously read memory pages and reuses them for subsequent reads, significantly reducing system calls and improving performance.

Add code object caching mechanism with a new code_object_generation field that tracks when code object caches need invalidation. This allows efficient reuse of parsed code object metadata and eliminates redundant processing of the same code objects across debugging sessions.

Optimize memory operations by replacing multiple individual structure copies with single bulk reads for the same data structures. This reduces the number of memory operations and system calls required to gather debugging information from the target process.

Update Makefile.pre.in to include Python/remote_debug.h in the headers list, ensuring that changes to the remote debugging header force proper recompilation of dependent modules and maintain build consistency across the codebase.

  • Issue: Async Call-Stack Reconstruction #91048

Sorry, something went wrong.

Uh oh!

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

All reactions
pablogsal added 2 commits May 25, 2025 14:07
@pablogsal
pythongh-91048: Refactor and optimize remote debugging module
38f9ad0
Completely refactor Modules/_remote_debugging_module.c with improved
code organization, replacing scattered reference counting and error
handling with centralized goto error paths. This cleanup improves
maintainability and reduces code duplication throughout the module while
preserving the same external API.

Implement memory page caching optimization in Python/remote_debug.h to
avoid repeated reads of the same memory regions during debugging
operations. The cache stores previously read memory pages and reuses
them for subsequent reads, significantly reducing system calls and
improving performance.

Add code object caching mechanism with a new code_object_generation
field in the interpreter state that tracks when code object caches need
invalidation. This allows efficient reuse of parsed code object metadata
and eliminates redundant processing of the same code objects across
debugging sessions.

Optimize memory operations by replacing multiple individual structure
copies with single bulk reads for the same data structures. This reduces
the number of memory operations and system calls required to gather
debugging information from the target process.

Update Makefile.pre.in to include Python/remote_debug.h in the headers
list, ensuring that changes to the remote debugging header force proper
recompilation of dependent modules and maintain build consistency across
the codebase.
@pablogsal
Fix free threading
a6fed05
@pablogsal
pablogsal requested review from 1st1, asvetlov, ericsnowcurrently, erlend-aasland, kumaraditya303, markshannon and willingc as code owners May 25, 2025 13:08
@bedevere-app bedevere-app Bot added the awaiting core review label May 25, 2025
@bedevere-app bedevere-app Bot mentioned this pull request May 25, 2025
Async Call-Stack Reconstruction #91048
Closed
@pablogsal pablogsal added the skip news label May 25, 2025
pablogsal added 2 commits May 25, 2025 14:12
@pablogsal
Fix lint
8c01234
@pablogsal
Simplify stuff and fix free threading caching
1130f27
@pablogsal
pablogsal force-pushed the profile-final branch from 86aab6d to 1130f27 Compare May 25, 2025 15:15
pablogsal added 3 commits May 25, 2025 17:09
@pablogsal
Fix clinic
e112a4a
@pablogsal
fix windows
559d44f
@pablogsal
Fix arm
5b4d67d
ambv
ambv approved these changes May 25, 2025
View reviewed changes

@ambv ambv left a comment

Copy link
Copy Markdown
Contributor

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.

It's not easy to look at the _remote_debugging_module.c diff given the number of changes, but I went through the module in a checkout and it looks much cleaner now.

I like the caching, I like free-threading handling, and the Unwinder object. I found a race in your test, I'll fix that for you alongside some trivial pep8 nits.

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread Lib/asyncio/tools.py Resolved

Uh oh!

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

Comment thread Lib/test/test_external_inspection.py Resolved

Uh oh!

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

Comment thread Modules/_remote_debugging_module.c Resolved

Uh oh!

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

Comment thread Modules/_remote_debugging_module.c Resolved

Uh oh!

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

Comment thread Modules/_remote_debugging_module.c Resolved

Uh oh!

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

Comment thread Objects/codeobject.c Resolved

Uh oh!

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

Comment thread Python/index_pool.c Resolved

Uh oh!

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

Comment thread Python/remote_debug.h 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 May 25, 2025
pablogsal and others added 9 commits May 25, 2025 17:31
@pablogsal
Fix lint
9033b20
@pablogsal
Small fix
db35f6e
@pablogsal
Simplofy cleanup
1773d78
@pablogsal
Small fix
e2ad532
@ambv
Fix race in test (two threads need two ready markers!)
eb61f38
@pablogsal
Fix windows
5da486c
@pablogsal
Fix windows
d6d0c7e
@pablogsal
Fix windows
5bdfec1
@pablogsal
Regen files
f463436
pablogsal and others added 2 commits May 25, 2025 19:06
@pablogsal
MOAR WINDOWS
416d96b
@pablogsal
Regen morefiles
681ab63
@pablogsal
pablogsal enabled auto-merge (squash) May 25, 2025 19:11
@pablogsal pablogsal added the needs backport to 3.14 bugs and security fixes label May 25, 2025
@pablogsal
pablogsal removed the request for review from 1st1 May 25, 2025 19:13
pablogsal and others added 2 commits May 25, 2025 20:27
@pablogsal
More windows stuff
14a5f58
@ambv
Regen frozenmain
89311c9
@pablogsal
pablogsal merged commit 42b25ad into python:main May 25, 2025
@pablogsal
pablogsal deleted the profile-final branch May 25, 2025 20:19
@bedevere-app bedevere-app Bot removed the awaiting merge label May 25, 2025
@miss-islington-app miss-islington-app Bot assigned pablogsal May 25, 2025
@bedevere-bot

This comment was marked as outdated.

Sign in to view
@pablogsal pablogsal added needs backport to 3.14 bugs and security fixes and removed needs backport to 3.14 bugs and security fixes labels May 25, 2025
@python python deleted a comment from miss-islington-app Bot May 25, 2025
@python python deleted a comment from miss-islington-app Bot May 25, 2025
@python python deleted a comment from miss-islington-app Bot May 25, 2025
@python python deleted a comment from miss-islington-app Bot May 25, 2025
pablogsal added a commit to pablogsal/cpython that referenced this pull request May 25, 2025
@pablogsal
pythongh-91048: Refactor and optimize remote debugging module (python…
21dc06e
…#134652)

Completely refactor Modules/_remote_debugging_module.c with improved
code organization, replacing scattered reference counting and error
handling with centralized goto error paths. This cleanup improves
maintainability and reduces code duplication throughout the module while
preserving the same external API.

Implement memory page caching optimization in Python/remote_debug.h to
avoid repeated reads of the same memory regions during debugging
operations. The cache stores previously read memory pages and reuses
them for subsequent reads, significantly reducing system calls and
improving performance.

Add code object caching mechanism with a new code_object_generation
field in the interpreter state that tracks when code object caches need
invalidation. This allows efficient reuse of parsed code object metadata
and eliminates redundant processing of the same code objects across
debugging sessions.

Optimize memory operations by replacing multiple individual structure
copies with single bulk reads for the same data structures. This reduces
the number of memory operations and system calls required to gather
debugging information from the target process.

Update Makefile.pre.in to include Python/remote_debug.h in the headers
list, ensuring that changes to the remote debugging header force proper
recompilation of dependent modules and maintain build consistency across
the codebase.

Also, make the module compatible with the free threading build as an extra :)

Co-authored-by: Łukasz Langa <[email protected]>

(cherry picked from commit 42b25ad)
@bedevere-app

bedevere-app Bot commented May 25, 2025

Copy link
Copy Markdown

GH-134673 is a backport of this pull request to the 3.14 branch.

All reactions

Sorry, something went wrong.

Uh oh!

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

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label May 25, 2025
pablogsal added a commit that referenced this pull request May 25, 2025
@pablogsal
[3.14] gh-91048: Refactor and optimize remote debugging module (#134652…
1822f33
…) (#134673)

gh-91048: Refactor and optimize remote debugging module (#134652)

Completely refactor Modules/_remote_debugging_module.c with improved
code organization, replacing scattered reference counting and error
handling with centralized goto error paths. This cleanup improves
maintainability and reduces code duplication throughout the module while
preserving the same external API.

Implement memory page caching optimization in Python/remote_debug.h to
avoid repeated reads of the same memory regions during debugging
operations. The cache stores previously read memory pages and reuses
them for subsequent reads, significantly reducing system calls and
improving performance.

Add code object caching mechanism with a new code_object_generation
field in the interpreter state that tracks when code object caches need
invalidation. This allows efficient reuse of parsed code object metadata
and eliminates redundant processing of the same code objects across
debugging sessions.

Optimize memory operations by replacing multiple individual structure
copies with single bulk reads for the same data structures. This reduces
the number of memory operations and system calls required to gather
debugging information from the target process.

Update Makefile.pre.in to include Python/remote_debug.h in the headers
list, ensuring that changes to the remote debugging header force proper
recompilation of dependent modules and maintain build consistency across
the codebase.

Also, make the module compatible with the free threading build as an extra :)

Co-authored-by: Łukasz Langa <[email protected]>

(cherry picked from commit 42b25ad)
@bedevere-bot

bedevere-bot commented May 25, 2025

Copy link
Copy Markdown

⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️

Hi! The buildbot iOS ARM64 Simulator 3.14 (tier-3) has failed when building commit 1822f33.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. Go to the page of the buildbot that failed (https://buildbot.python.org/#/builders/1722/builds/161) and take a look at the build logs.
  4. Check if the failure is related to this commit (1822f33) or if it is a false positive.
  5. If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.

You can take a look at the buildbot page here:

https://buildbot.python.org/#/builders/1722/builds/161

Summary of the results of the build (if available):

Click to see traceback logs
remote: Enumerating objects: 60, done.        
remote: Counting objects:   1% (1/60)        
remote: Counting objects:   3% (2/60)        
remote: Counting objects:   5% (3/60)        
remote: Counting objects:   6% (4/60)        
remote: Counting objects:   8% (5/60)        
remote: Counting objects:  10% (6/60)        
remote: Counting objects:  11% (7/60)        
remote: Counting objects:  13% (8/60)        
remote: Counting objects:  15% (9/60)        
remote: Counting objects:  16% (10/60)        
remote: Counting objects:  18% (11/60)        
remote: Counting objects:  20% (12/60)        
remote: Counting objects:  21% (13/60)        
remote: Counting objects:  23% (14/60)        
remote: Counting objects:  25% (15/60)        
remote: Counting objects:  26% (16/60)        
remote: Counting objects:  28% (17/60)        
remote: Counting objects:  30% (18/60)        
remote: Counting objects:  31% (19/60)        
remote: Counting objects:  33% (20/60)        
remote: Counting objects:  35% (21/60)        
remote: Counting objects:  36% (22/60)        
remote: Counting objects:  38% (23/60)        
remote: Counting objects:  40% (24/60)        
remote: Counting objects:  41% (25/60)        
remote: Counting objects:  43% (26/60)        
remote: Counting objects:  45% (27/60)        
remote: Counting objects:  46% (28/60)        
remote: Counting objects:  48% (29/60)        
remote: Counting objects:  50% (30/60)        
remote: Counting objects:  51% (31/60)        
remote: Counting objects:  53% (32/60)        
remote: Counting objects:  55% (33/60)        
remote: Counting objects:  56% (34/60)        
remote: Counting objects:  58% (35/60)        
remote: Counting objects:  60% (36/60)        
remote: Counting objects:  61% (37/60)        
remote: Counting objects:  63% (38/60)        
remote: Counting objects:  65% (39/60)        
remote: Counting objects:  66% (40/60)        
remote: Counting objects:  68% (41/60)        
remote: Counting objects:  70% (42/60)        
remote: Counting objects:  71% (43/60)        
remote: Counting objects:  73% (44/60)        
remote: Counting objects:  75% (45/60)        
remote: Counting objects:  76% (46/60)        
remote: Counting objects:  78% (47/60)        
remote: Counting objects:  80% (48/60)        
remote: Counting objects:  81% (49/60)        
remote: Counting objects:  83% (50/60)        
remote: Counting objects:  85% (51/60)        
remote: Counting objects:  86% (52/60)        
remote: Counting objects:  88% (53/60)        
remote: Counting objects:  90% (54/60)        
remote: Counting objects:  91% (55/60)        
remote: Counting objects:  93% (56/60)        
remote: Counting objects:  95% (57/60)        
remote: Counting objects:  96% (58/60)        
remote: Counting objects:  98% (59/60)        
remote: Counting objects: 100% (60/60)        
remote: Counting objects: 100% (60/60), done.        
remote: Compressing objects:   7% (1/14)        
remote: Compressing objects:  14% (2/14)        
remote: Compressing objects:  21% (3/14)        
remote: Compressing objects:  28% (4/14)        
remote: Compressing objects:  35% (5/14)        
remote: Compressing objects:  42% (6/14)        
remote: Compressing objects:  50% (7/14)        
remote: Compressing objects:  57% (8/14)        
remote: Compressing objects:  64% (9/14)        
remote: Compressing objects:  71% (10/14)        
remote: Compressing objects:  78% (11/14)        
remote: Compressing objects:  85% (12/14)        
remote: Compressing objects:  92% (13/14)        
remote: Compressing objects: 100% (14/14)        
remote: Compressing objects: 100% (14/14), done.        
remote: Total 31 (delta 27), reused 19 (delta 17), pack-reused 0 (from 0)        
From https://github.com/python/cpython
 * branch                    3.14       -> FETCH_HEAD
Note: switching to '1822f33b1af989ebb9e7a5b58bd40721fca9a218'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:

  git switch -c <new-branch-name>

Or undo this operation with:

  git switch -

Turn off this advice by setting config variable advice.detachedHead to false

HEAD is now at 1822f33b1af [3.14] gh-91048: Refactor and optimize remote debugging module (#134652) (#134673)
Switched to and reset branch '3.14'

configure: WARNING: no system libmpdecimal found; falling back to bundled libmpdecimal (deprecated and scheduled for removal in Python 3.15)
configure: WARNING: pkg-config is missing. Some dependencies may not be detected correctly.

configure: WARNING: no system libmpdecimal found; falling back to bundled libmpdecimal (deprecated and scheduled for removal in Python 3.15)
configure: WARNING: pkg-config is missing. Some dependencies may not be detected correctly.

In file included from ../../Modules/_remote_debugging_module.c:31:
../../Modules/../Python/remote_debug.h:139:20: error: call to undeclared function 'pid_to_task'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
  139 |     handle->task = pid_to_task(handle->pid);
      |                    ^
1 error generated.
make: *** [Modules/_remote_debugging_module.o] Error 1
All reactions

Sorry, something went wrong.

Uh oh!

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

@freakboy3742

freakboy3742 commented May 26, 2025

Copy link
Copy Markdown
Contributor

iOS build failure seems to be due to a discrepancy between the #define for the pid_to_task prototype, and the usage. Trying a fix now.

All reactions

Sorry, something went wrong.

Uh oh!

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

@freakboy3742 freakboy3742 mentioned this pull request May 26, 2025
gh-91048: Correct Apple platform includes for iOS #134712
Merged
Pranjal095 pushed a commit to Pranjal095/cpython that referenced this pull request Jul 12, 2025
@pablogsal @ambv @Pranjal095
pythongh-91048: Refactor and optimize remote debugging module (python…
4141cc7
…#134652)

Completely refactor Modules/_remote_debugging_module.c with improved
code organization, replacing scattered reference counting and error
handling with centralized goto error paths. This cleanup improves
maintainability and reduces code duplication throughout the module while
preserving the same external API.

Implement memory page caching optimization in Python/remote_debug.h to
avoid repeated reads of the same memory regions during debugging
operations. The cache stores previously read memory pages and reuses
them for subsequent reads, significantly reducing system calls and
improving performance.

Add code object caching mechanism with a new code_object_generation
field in the interpreter state that tracks when code object caches need
invalidation. This allows efficient reuse of parsed code object metadata
and eliminates redundant processing of the same code objects across
debugging sessions.

Optimize memory operations by replacing multiple individual structure
copies with single bulk reads for the same data structures. This reduces
the number of memory operations and system calls required to gather
debugging information from the target process.

Update Makefile.pre.in to include Python/remote_debug.h in the headers
list, ensuring that changes to the remote debugging header force proper
recompilation of dependent modules and maintain build consistency across
the codebase.

Also, make the module compatible with the free threading build as an extra :)

Co-authored-by: Łukasz Langa <[email protected]>
taegyunkim pushed a commit to taegyunkim/cpython that referenced this pull request Aug 4, 2025
@pablogsal @ambv @taegyunkim
pythongh-91048: Refactor and optimize remote debugging module (python…
7f1d15f
…#134652)

Completely refactor Modules/_remote_debugging_module.c with improved
code organization, replacing scattered reference counting and error
handling with centralized goto error paths. This cleanup improves
maintainability and reduces code duplication throughout the module while
preserving the same external API.

Implement memory page caching optimization in Python/remote_debug.h to
avoid repeated reads of the same memory regions during debugging
operations. The cache stores previously read memory pages and reuses
them for subsequent reads, significantly reducing system calls and
improving performance.

Add code object caching mechanism with a new code_object_generation
field in the interpreter state that tracks when code object caches need
invalidation. This allows efficient reuse of parsed code object metadata
and eliminates redundant processing of the same code objects across
debugging sessions.

Optimize memory operations by replacing multiple individual structure
copies with single bulk reads for the same data structures. This reduces
the number of memory operations and system calls required to gather
debugging information from the target process.

Update Makefile.pre.in to include Python/remote_debug.h in the headers
list, ensuring that changes to the remote debugging header force proper
recompilation of dependent modules and maintain build consistency across
the codebase.

Also, make the module compatible with the free threading build as an extra :)

Co-authored-by: Łukasz Langa <[email protected]>
gostak-dd pushed a commit to gostak-dd/cpython that referenced this pull request Jun 2, 2026
@pablogsal @ambv @gostak-dd
pythongh-91048: Refactor and optimize remote debugging module (python…
624cf34
…#134652)

Completely refactor Modules/_remote_debugging_module.c with improved
code organization, replacing scattered reference counting and error
handling with centralized goto error paths. This cleanup improves
maintainability and reduces code duplication throughout the module while
preserving the same external API.

Implement memory page caching optimization in Python/remote_debug.h to
avoid repeated reads of the same memory regions during debugging
operations. The cache stores previously read memory pages and reuses
them for subsequent reads, significantly reducing system calls and
improving performance.

Add code object caching mechanism with a new code_object_generation
field in the interpreter state that tracks when code object caches need
invalidation. This allows efficient reuse of parsed code object metadata
and eliminates redundant processing of the same code objects across
debugging sessions.

Optimize memory operations by replacing multiple individual structure
copies with single bulk reads for the same data structures. This reduces
the number of memory operations and system calls required to gather
debugging information from the target process.

Update Makefile.pre.in to include Python/remote_debug.h in the headers
list, ensuring that changes to the remote debugging header force proper
recompilation of dependent modules and maintain build consistency across
the codebase.

Also, make the module compatible with the free threading build as an extra :)

Co-authored-by: Łukasz Langa <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@ambv ambv ambv approved these changes
@ericsnowcurrently ericsnowcurrently Awaiting requested review from ericsnowcurrently ericsnowcurrently is a code owner
@markshannon markshannon Awaiting requested review from markshannon markshannon is a code owner
@asvetlov asvetlov Awaiting requested review from asvetlov asvetlov is a code owner
@kumaraditya303 kumaraditya303 Awaiting requested review from kumaraditya303 kumaraditya303 is a code owner
@willingc willingc Awaiting requested review from willingc willingc is a code owner
@erlend-aasland erlend-aasland Awaiting requested review from erlend-aasland erlend-aasland is a code owner

Uh oh!

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

Assignees

@pablogsal pablogsal

Labels

skip news

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

@pablogsal @bedevere-bot @freakboy3742 @ambv
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.