From e3564689a59886f347e0b44d5296320d9fdd9039 Mon Sep 17 00:00:00 2001 From: Tian Gao Date: Thu, 20 Mar 2025 20:31:55 -0400 Subject: [PATCH] gh-120144: Disable the CALL event when possible to achieve zero overhead pdb (#131390) --- Lib/bdb.py | 7 ++++++- .../Library/2025-03-18-02-11-33.gh-issue-120144.dBLFkI.rst | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/Library/2025-03-18-02-11-33.gh-issue-120144.dBLFkI.rst diff --git a/Lib/bdb.py b/Lib/bdb.py index d32a05f59ad6..ba5cacc2a54c 100644 --- a/Lib/bdb.py +++ b/Lib/bdb.py @@ -342,7 +342,12 @@ class Bdb: self.botframe = frame.f_back # (CT) Note that this may also be None! return self.trace_dispatch if not (self.stop_here(frame) or self.break_anywhere(frame)): - # No need to trace this function + # We already know there's no breakpoint in this function + # If it's a next/until/return command, we don't need any CALL event + # and we don't need to set the f_trace on any new frame. + # If it's a step command, it must either hit stop_here, or skip the + # whole module. Either way, we don't need the CALL event here. + self.disable_current_event() return # None # Ignore call events in generator except when stepping. if self.stopframe and frame.f_code.co_flags & GENERATOR_AND_COROUTINE_FLAGS: diff --git a/Misc/NEWS.d/next/Library/2025-03-18-02-11-33.gh-issue-120144.dBLFkI.rst b/Misc/NEWS.d/next/Library/2025-03-18-02-11-33.gh-issue-120144.dBLFkI.rst new file mode 100644 index 000000000000..35d577e23510 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2025-03-18-02-11-33.gh-issue-120144.dBLFkI.rst @@ -0,0 +1 @@ +Disable ``CALL`` event in :mod:`bdb` in ``monitoring`` backend when we don't need any new events on the code object to get a better performance. -- 2.47.3