Skip to content

Commit

Permalink
Push caching to parent frame, and cache more frames. (#14418)
Browse files Browse the repository at this point in the history
I hope in deep code this makes things faster.

Complement to #14386, but a bit of a blind fix.
  • Loading branch information
Carreau committed Apr 26, 2024
2 parents f68c737 + ffb66ee commit afae901
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions IPython/core/debugger.py
Original file line number Diff line number Diff line change
Expand Up @@ -922,19 +922,31 @@ def _is_in_decorator_internal_and_should_skip(self, frame):

return self._cachable_skip(frame)

@lru_cache
@lru_cache(1024)
def _cached_one_parent_frame_debuggerskip(self, frame):
"""
Cache looking up for DEBUGGERSKIP on parent frame.
This should speedup walking through deep frame when one of the highest
one does have a debugger skip.
This is likely to introduce fake positive though.
"""
while getattr(frame, "f_back", None):
frame = frame.f_back
if self._get_frame_locals(frame).get(DEBUGGERSKIP):
return True
return None

@lru_cache(1024)
def _cachable_skip(self, frame):
# if frame is tagged, skip by default.
if DEBUGGERSKIP in frame.f_code.co_varnames:
return True

# if one of the parent frame value set to True skip as well.

cframe = frame
while getattr(cframe, "f_back", None):
cframe = cframe.f_back
if self._get_frame_locals(cframe).get(DEBUGGERSKIP):
return True
if self._cached_one_parent_frame_debuggerskip(frame):
return True

return False

Expand Down

0 comments on commit afae901

Please sign in to comment.