Skip to content

Commit

Permalink
Cache debugger skip frame predicate (#14386)
Browse files Browse the repository at this point in the history
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.

See spyder-ide/spyder-kernels#458,
#13972,
spyder-ide/spyder#20571,
#14382
  • Loading branch information
Carreau committed Apr 2, 2024
2 parents f9e1ccb + 59673f3 commit a3074b8
Showing 1 changed file with 19 additions and 20 deletions.
39 changes: 19 additions & 20 deletions IPython/core/debugger.py
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
Pdb debugger class.
Expand Down Expand Up @@ -101,17 +100,25 @@
#
#*****************************************************************************

from __future__ import annotations

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

from typing import TYPE_CHECKING

if TYPE_CHECKING:
# otherwise circular import
from IPython.core.interactiveshell import InteractiveShell

# skip module docstests
__skip_doctest__ = True
Expand Down Expand Up @@ -191,6 +198,8 @@ class Pdb(OldPdb):
"""

shell: InteractiveShell

if CHAIN_EXCEPTIONS:
MAX_CHAINED_EXCEPTION_DEPTH = 999

Expand Down Expand Up @@ -471,24 +480,11 @@ def precmd(self, line):

return line

def new_do_frame(self, arg):
OldPdb.do_frame(self, arg)

def new_do_quit(self, arg):

if hasattr(self, 'old_all_completions'):
self.shell.Completer.all_completions = self.old_all_completions

return OldPdb.do_quit(self, arg)

do_q = do_quit = decorate_fn_with_doc(new_do_quit, OldPdb.do_quit)

def new_do_restart(self, arg):
"""Restart command. In the context of ipython this is exactly the same
thing as 'quit'."""
self.msg("Restart doesn't make sense here. Using 'quit' instead.")
return self.do_quit(arg)

def print_stack_trace(self, context=None):
Colors = self.color_scheme_table.active_colors
ColorsNormal = Colors.Normal
Expand Down Expand Up @@ -941,11 +937,14 @@ def _is_in_decorator_internal_and_should_skip(self, frame):
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
Expand Down

0 comments on commit a3074b8

Please sign in to comment.