8000 gh-120144: Disable the CALL event when possible to achieve zero overhead pdb by gaogaotiantian · Pull Request #131390 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-120144: Disable the CALL event when possible to achieve zero overhead pdb #131390

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 21, 2025

Conversation

gaogaotiantian
Copy link
Member
@gaogaotiantian gaogaotiantian commented Mar 18, 2025

This is one line of well-thought code :)

We basically solved the debugger overhead in a big loop by disabling LINE events, the one (major) thing left was recursive calls - or rather, calls in general. We won't prevent CALL events from happening for every unrelated call because that would require a much larger change, but we can disable CALL events after we hit it once.

Notice that CALL event has a two effects which made it a bit more complicated:

  1. It could be the event that the user actually wants (only happens in step)
  2. It returns the local trace function that enables all the other events on this code object (not function/frame).

No 2. makes it a bit challenging and much more rewarding.

We need to make sure we don't need any new events on this code object, before we can disable the CALL event.

First of all, if there's any breakpoint on the code object, we can't do that. But we already have check for that where the code was added.

Then we'll realize, if it's a next, until or return - it will just work fine, because they all rely on events on existing frame and code objects. It's impossible for those commands to stop at a new frame.

The only command that could stop at a new frame, is step - but if it's a step, it would either

  • hit stop_here() already on this specific CALL event so we can't reach to this point
  • or skip this function because of specified skip argument, which means it won't stop in this function in the future

So really, we don't need to care about anything. If we don't need to trace this function now, we won't need any new events for this code object in the future (until the user interaction), so we can simply disable the CALL event.

This basically gives us a zero overhead debugger. There's no observable overhead for the recursive fib implementation.

@gaogaotiantian gaogaotiantian merged commit e356468 into python:main Mar 21, 2025
43 checks passed
@gaogaotiantian gaogaotiantian deleted the disable-more-events branch March 21, 2025 00:32
seehwan pushed a commit to seehwan/cpython that referenced this pull request Apr 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0