https://github.com/python/cpython/commit/6c9f2b691aaf0cf88cf2c3ba862f5de237a17344
commit: 6c9f2b691aaf0cf88cf2c3ba862f5de237a17344
branch: main
author: Maurycy Pawłowski-Wieroński <[email protected]>
committer: pablogsal <[email protected]>
date: 2026-11-19T03:15:53Z
summary:

gh-149584: Stop rereading the base frame sentinel in _remote_debugging (#159124)

Skip the remote read of the base frame sentinel while preserving the GC marker 
and complete-stack checks.

files:
A Misc/NEWS.d/next/Library/2026-10-10-13-35-08.gh-issue-149584.Yq2bF7.rst
M Modules/_remote_debugging/frame_cache.c
M Modules/_remote_debugging/frames.c

diff --git 
a/Misc/NEWS.d/next/Library/2026-10-10-13-35-08.gh-issue-149584.Yq2bF7.rst 
b/Misc/NEWS.d/next/Library/2026-10-10-13-35-08.gh-issue-149584.Yq2bF7.rst
new file mode 100644
index 00000000000000..7f92a1b19877cd
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2026-10-10-13-35-08.gh-issue-149584.Yq2bF7.rst
@@ -0,0 +1,2 @@
+Improve the performance of the Tachyon profiler by avoiding unnecessary remote
+reads of the base frame sentinel. Patch by Maurycy Pawłowski-Wieroński.
diff --git a/Modules/_remote_debugging/frame_cache.c 
b/Modules/_remote_debugging/frame_cache.c
index 1b2d9a60f408b9..63d1331015a548 100644
--- a/Modules/_remote_debugging/frame_cache.c
+++ b/Modules/_remote_debugging/frame_cache.c
@@ -318,9 +318,8 @@ frame_cache_store(
     // Validate we have a complete stack before caching.
     // Only cache if last_frame_visited matches base_frame_addr (the sentinel
     // at the bottom of the stack). Note: we use last_frame_visited rather than
-    // addrs[num_addrs-1] because the base frame is visited but not added to 
the
-    // addrs array (it returns frame==NULL from is_frame_valid due to
-    // owner==FRAME_OWNED_BY_INTERPRETER).
+    // addrs[num_addrs-1] because the base frame's address is not added to the
+    // addrs array.
     if (base_frame_addr != 0 && last_frame_visited != base_frame_addr) {
         // Incomplete stack - don't cache (graceful degradation)
         return 0;
diff --git a/Modules/_remote_debugging/frames.c 
b/Modules/_remote_debugging/frames.c
index da2d9f865e536f..3f8d628a6314e6 100644
--- a/Modules/_remote_debugging/frames.c
+++ b/Modules/_remote_debugging/frames.c
@@ -294,6 +294,14 @@ process_frame_chain(
         }
         assert(frame_count <= MAX_FRAME_CHAIN_DEPTH);
 
+        // The base frame is a sentinel with previous == NULL: reaching it is
+        // enough, no need to read it. Still read it when it is the GC frame
+        // so the <GC> marker gets emitted.
+        if (frame_addr == ctx->base_frame_addr
+                && !(unwinder->gc && frame_addr == ctx->gc_frame)) {
+            break;
+        }
+
         if (ctx->chunks && ctx->chunks->count > 0) {
             parse_result = parse_frame_from_chunks(
                 unwinder, &frame, frame_addr, &next_frame_addr, ctx->chunks);

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to