Breakpoints cause enormous slowdown

Tim Peters tim.one at home.com
Mon Oct 29 02:24:17 EST 2001


[Bruce Dawson]
> I've been playing around with PythonWin and a proprietary debugger with
> a common derivation, and they both have a serious problem. I'm worried
> that this problem may be fundamental to Python debuggers.
> ...
> However, if I leave the breakpoint in place then ...
> the performance drops by approximately five hundred to one!!!
> ...
> My understanding is that when there is a breakpoint set that the
> debugger has to run in a single step mode and check a list of
> breakpoints after each instruction. If that is so then a 500:1 drop in
> performance is not surprising.

"Single step" is actually "single line", or, more precisely, "once per
SET_LINENO opcode", and each involves a callback into the Python code that
implements the debugger (assuming it's pdb-like).  You can read a bit about
this in the "How it Works" subsection of the Python Debugger chapter in the
Library manual.

> ...
> Other language/debugger pairs frequently solve this problem with a
> breakpoint instruction.
> ...
> Has this been discussed before? Is this possible?

Yes and yes.  Nobody has implemented it, though, and there are
(surmountable) technical difficulties facing whoever tries.  A good solution
would make SET_LINENO opcodes history (indeed, they're not needed now for
anything *except* driving debuggers and tracers -- line numbers in
tracebacks don't rely on SET_LINENO).

> The benefits would be huge. Right now there are some classes of problems
> that cannot be debugged with a debugger in Python because of the
> tremendous slowdowns that occur.

I confess I haven't used the Python debugger in many years -- a judicious
'print' statement or two coupled with thought usually solves problems
quickly.  Ditto for debugging C code, for that matter.  I'm not recommending
that you do likewise, just explaining why I've never felt an urge to "do
something about the debuggger problem".  But I assume much the same applies
to most of The Usual Contributing Suspects, since the debugger is rarely a
topic of conversation.

patches-appreciated-ly y'rs  - tim





More information about the Python-list mailing list