Skip to content

Conversation

@youtux
Copy link

@youtux youtux commented Dec 19, 2025

Changes Made

See https://gist.github.com/youtux/f21934bda02366ca4eda898e3d92cf52 for a more detailed breakdown.

These bugs and performance fixes have been addressed using Claude Code.

Performance Impact

  • Improved step execution time from seconds to instantaneous.

… line events

Fixes several performance issues in PEP 669 tracing implementation:

Bug fixes:
- Module-level breakpoints (func_name='None') were enabling line tracing
  for all functions in the file, even when the breakpoint was outside
  the function's line range. Now checks if breakpoint falls within the
  function's boundaries (co_firstlineno to last line from co_lines()).
- CALL event monitoring was never disabled after breakpoints were
  discovered, causing unnecessary overhead. Now removes CALL monitoring
  once breakpoint is processed via remove_breakpoint().
- Missing f_back breakpoint tracking prevented proper return event
  registration when parent frame had breakpoints. Now checks f_back
  for matching breakpoints.
- Frame cache key was added to global_cache_skips even when line tracing
  was enabled, causing frames with breakpoints to be incorrectly skipped.
  Now only caches frames that should actually be skipped.
- Expensive py_start_callback checks (disposed, thread liveness, path
  normalization, file type) were performed before cache lookup. Now
  checks cache first for better performance.
- Line cache key wasn't being used to skip already-checked lines with no
  breakpoints. Now caches negative results at line granularity.
- Stack walking on every exception to find top-level frame was O(n)
  instead of O(1). Added _is_top_level_frame() helper to check frame
  properties directly without walking the entire stack.

Performance impact: Internal benchmark shows step execution time reduced
from several seconds to near-instantaneous in files with selective
breakpoints (e.g., breakpoint in one function no longer slows down all
other functions in the same file).
@youtux youtux changed the title Optimize python tracing performance Optimize python tracing debugger performance Dec 19, 2025
@BartvHelvert
Copy link
Member

Hi, please create an issue in our issue tracker and describe the exact problem you are trying to solve.

https://youtrack.jetbrains.com/issues/PY

@youtux
Copy link
Author

youtux commented Dec 19, 2025

@youtux
Copy link
Author

youtux commented Dec 19, 2025

@BartvHelvert BartvHelvert added the PyCharm Pull requests for PyCharm label Dec 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PyCharm Pull requests for PyCharm

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants