[ZODB-Dev] [Report] ZEO (Client+Server together) spends almost 25% of time in code controlled by "if __debug__:"

Dieter Maurer dieter at handshake.de
Sun Nov 16 13:21:14 EST 2003


ZODB3.1 + Python 2.1.3

Recently, I analysed ZEO communication efficiency (as we have
still unexplained non-deterministic problems (50 to 90 % of the time
spent in ZEO operations)).

I found out, that a heavily ZEO centric operation (reading about 120.000 keys
from a "BTrees.OOBTree.OOBTree" instance) is sped up by almost
25% when Python's "__debug__" is set to false
(after I had fixed the quadratic runtime behaviour in "short_repr").

Python's "__debug__" is automatically set to "0" when Python is
run with "-O" option. However, in this case, Python is using
"optimized" byte codes without "SET_LINENO" instructions.
I fear, this will make debugging impossible (Python 2.3 may be
debuggable without "SET_LINENO" instructions, but I am not sure).
Therefore, I would not like to run Zope with "-O".

I hacked "zLOG/__init__.py" to set "__debug__" to "None"
in case the log level is ">= 0" and "zdaemon/Daemon.py"
to start python in optimized mode only when "__debug__ == 0".
I know that "<PythonDoc>/ref/assert.html" states that
assignment to "__debug__" is illegal. For Python 2.1.3,
however, there seem to be no problem as the interpreter
apparently uses an internal variable for its purposes.


Maybe, code should avoid "if __debug__:" conditions to
protect expensive operations and use
its own "if doDebug:" conditions instead?


-- 
Dieter



More information about the ZODB-Dev mailing list