[Python-Dev] Optimizing with.

Jeffrey Yasskin jyasskin at gmail.com
Thu Mar 6 04:35:28 CET 2008


I've got a patch in http://bugs.python.org/issue2179 that optimizes
the bytecode generated by a with statement by tucking the
context_manager.__exit__ method onto the stack. It saves 2 opcodes, 8
bytes, and about .5us for each with block at the cost of an extra
stack entry for the duration of the block. Since it's the first time
I've touched the core of the compiler and interpreter, I'm hoping that
someone can take a look before I check it in.

Thanks!
Jeffrey


More information about the Python-Dev mailing list