From ffb66eeb010580b71b99f3a843f7f20411ef2edf Mon Sep 17 00:00:00 2001 From: Matthias Bussonnier Date: Thu, 25 Apr 2024 15:24:41 +0200 Subject: [PATCH] Push caching to parent frame, and cache more frames. I hope in deep code this makes things faster. Complement to #14386, but a bit of a blind fix. --- IPython/core/debugger.py | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/IPython/core/debugger.py b/IPython/core/debugger.py index 59cf24c6a5..0a524ebe40 100644 --- a/IPython/core/debugger.py +++ b/IPython/core/debugger.py @@ -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