Zero runtime impact tracing

Johannes Bauer dfnsonfsduifb at gmx.de
Sat Jul 30 04:32:10 EDT 2016


Hi group,

I'm using CPython 3.5.1. Currently I'm writing some delicate code that
is doing the right thing in 99% of the cases and screws up on the other 1%.

I would like to have tracing in some very inner loops:

if self._debug:
   print("Offset %d foo bar" % (self._offset))

However, this incurs a hefty performance penalty even when tracing disabled.

What I want is that the if clause completely disappears during bytecode
compilation if self._debug is not set. Is there any way that I can tell
the optimizer that this variable will either be set once, but never
change during runtime and that it can go ahead and completely remove the
code when self._debug is False?

Any other means of signalling the it should compile the tracing code in
would also be fine by me (e.g, calling Python with some command line
options or such). As long as during normal operation, there is no
performance impact.

Cheers,
Johannes

-- 
>> Wo hattest Du das Beben nochmal GENAU vorhergesagt?
> Zumindest nicht öffentlich!
Ah, der neueste und bis heute genialste Streich unsere großen
Kosmologen: Die Geheim-Vorhersage.
 - Karl Kaos über Rüdiger Thomas in dsa <hidbv3$om2$1 at speranza.aioe.org>



More information about the Python-list mailing list