From 49a765239bf20d91561c341646abe251b8123e9a 2024-04-02 09:31:12 From: Matthias Bussonnier Date: 2024-04-02 09:31:12 Subject: [PATCH] Cache debugger skip frame predicate I'm not 100% sure this is correct as technically the value of __debugger_skip__ could change in the current frame while we are stepping into it, but that is likely super rare, and the slowdown that this create is problematic. There is still a small overhead for me, but this should make the experience much better. --- diff --git a/IPython/core/debugger.py b/IPython/core/debugger.py index d7ace4c..0442a98 100644 --- a/IPython/core/debugger.py +++ b/IPython/core/debugger.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """ Pdb debugger class. @@ -103,15 +102,15 @@ All the changes since then are under the same license as IPython. import inspect import linecache -import sys -import re import os +import re +import sys +from contextlib import contextmanager +from functools import lru_cache from IPython import get_ipython -from contextlib import contextmanager -from IPython.utils import PyColorize -from IPython.utils import coloransi, py3compat from IPython.core.excolors import exception_colors +from IPython.utils import PyColorize, coloransi, py3compat # skip module docstests __skip_doctest__ = True @@ -941,11 +940,14 @@ class Pdb(OldPdb): Utility to tell us whether we are in a decorator internal and should stop. """ - # if we are disabled don't skip if not self._predicates["debuggerskip"]: return False + return self._cachable_skip(frame) + + @lru_cache + def _cachable_skip(self, frame): # if frame is tagged, skip by default. if DEBUGGERSKIP in frame.f_code.co_varnames: return True