Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
pablogsal merged 20 commits intopython:mainfrompablogsal:profile-final
May 25, 2025

Conversation

pablogsal
Copy link
Member

@pablogsalpablogsal commentedMay 25, 2025
edited
Loading

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.

Completely refactor Modules/_remote_debugging_module.c with improvedcode organization, replacing scattered reference counting and errorhandling with centralized goto error paths. This cleanup improvesmaintainability and reduces code duplication throughout the module whilepreserving the same external API.Implement memory page caching optimization in Python/remote_debug.h toavoid repeated reads of the same memory regions during debuggingoperations. The cache stores previously read memory pages and reusesthem for subsequent reads, significantly reducing system calls andimproving performance.Add code object caching mechanism with a new code_object_generationfield in the interpreter state that tracks when code object caches needinvalidation. This allows efficient reuse of parsed code object metadataand eliminates redundant processing of the same code objects acrossdebugging sessions.Optimize memory operations by replacing multiple individual structurecopies with single bulk reads for the same data structures. This reducesthe number of memory operations and system calls required to gatherdebugging information from the target process.Update Makefile.pre.in to include Python/remote_debug.h in the headerslist, ensuring that changes to the remote debugging header force properrecompilation of dependent modules and maintain build consistency acrossthe codebase.
Copy link
Contributor

@ambvambv left a 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.

@pablogsalpablogsalenabled auto-merge (squash)May 25, 2025 19:11
@pablogsalpablogsal added the needs backport to 3.14bugs and security fixes labelMay 25, 2025
@pablogsalpablogsal removed the request for review from1st1May 25, 2025 19:13
@pablogsalpablogsal merged commit42b25ad intopython:mainMay 25, 2025
38 checks passed
@pablogsalpablogsal deleted the profile-final branchMay 25, 2025 20:19
@bedevere-bot

This comment was marked as outdated.

@pablogsalpablogsal added needs backport to 3.14bugs and security fixes and removed needs backport to 3.14bugs and security fixes labelsMay 25, 2025
@pythonpython deleted a comment frommiss-islington-appbotMay 25, 2025
@pythonpython deleted a comment frommiss-islington-appbotMay 25, 2025
@pythonpython deleted a comment frommiss-islington-appbotMay 25, 2025
@pythonpython deleted a comment frommiss-islington-appbotMay 25, 2025
pablogsal added a commit to pablogsal/cpython that referenced this pull requestMay 25, 2025
…#134652)Completely refactor Modules/_remote_debugging_module.c with improvedcode organization, replacing scattered reference counting and errorhandling with centralized goto error paths. This cleanup improvesmaintainability and reduces code duplication throughout the module whilepreserving the same external API.Implement memory page caching optimization in Python/remote_debug.h toavoid repeated reads of the same memory regions during debuggingoperations. The cache stores previously read memory pages and reusesthem for subsequent reads, significantly reducing system calls andimproving performance.Add code object caching mechanism with a new code_object_generationfield in the interpreter state that tracks when code object caches needinvalidation. This allows efficient reuse of parsed code object metadataand eliminates redundant processing of the same code objects acrossdebugging sessions.Optimize memory operations by replacing multiple individual structurecopies with single bulk reads for the same data structures. This reducesthe number of memory operations and system calls required to gatherdebugging information from the target process.Update Makefile.pre.in to include Python/remote_debug.h in the headerslist, ensuring that changes to the remote debugging header force properrecompilation of dependent modules and maintain build consistency acrossthe codebase.Also, make the module compatible with the free threading build as an extra :)Co-authored-by: Łukasz Langa <lukasz@langa.pl>(cherry picked from commit42b25ad)
@bedevere-app
Copy link

GH-134673 is a backport of this pull request to the3.14 branch.

@bedevere-appbedevere-appbot removed the needs backport to 3.14bugs and security fixes labelMay 25, 2025
pablogsal added a commit that referenced this pull requestMay 25, 2025
…) (#134673)gh-91048: Refactor and optimize remote debugging module (#134652)Completely refactor Modules/_remote_debugging_module.c with improvedcode organization, replacing scattered reference counting and errorhandling with centralized goto error paths. This cleanup improvesmaintainability and reduces code duplication throughout the module whilepreserving the same external API.Implement memory page caching optimization in Python/remote_debug.h toavoid repeated reads of the same memory regions during debuggingoperations. The cache stores previously read memory pages and reusesthem for subsequent reads, significantly reducing system calls andimproving performance.Add code object caching mechanism with a new code_object_generationfield in the interpreter state that tracks when code object caches needinvalidation. This allows efficient reuse of parsed code object metadataand eliminates redundant processing of the same code objects acrossdebugging sessions.Optimize memory operations by replacing multiple individual structurecopies with single bulk reads for the same data structures. This reducesthe number of memory operations and system calls required to gatherdebugging information from the target process.Update Makefile.pre.in to include Python/remote_debug.h in the headerslist, ensuring that changes to the remote debugging header force properrecompilation of dependent modules and maintain build consistency acrossthe codebase.Also, make the module compatible with the free threading build as an extra :)Co-authored-by: Łukasz Langa <lukasz@langa.pl>(cherry picked from commit42b25ad)
@bedevere-bot
Copy link

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

Hi! The buildbotiOS ARM64 Simulator 3.14 (tier-3) has failed when building commit1822f33.

What do you need to do:

  1. Don't panic.
  2. Checkthe 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_HEADNote:switching to '1822f33b1af989ebb9e7a5b58bd40721fca9a218'.You are in 'detached HEAD' state. You can look around, make experimentalchanges and commit them, and you can discard any commits you make in thisstate without impacting any branches by switching back to a branch.If you want to create a new branch to retain commits you create, you maydo 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 falseHEAD 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

@freakboy3742
Copy link
Contributor

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

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@ambvambvambv approved these changes

@ericsnowcurrentlyericsnowcurrentlyAwaiting requested review from ericsnowcurrentlyericsnowcurrently is a code owner

@markshannonmarkshannonAwaiting requested review from markshannonmarkshannon is a code owner

@asvetlovasvetlovAwaiting requested review from asvetlovasvetlov is a code owner

@kumaraditya303kumaraditya303Awaiting requested review from kumaraditya303kumaraditya303 is a code owner

@willingcwillingcAwaiting requested review from willingcwillingc is a code owner

@erlend-aaslanderlend-aaslandAwaiting requested review from erlend-aaslanderlend-aasland is a code owner

Assignees

@pablogsalpablogsal

Labels
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

4 participants
@pablogsal@bedevere-bot@freakboy3742@ambv

[8]ページ先頭

©2009-2025 Movatter.jp