[Python-Dev] Suggest reverting today's checkin (recursive constant folding in the peephole optimizer)

Raymond Hettinger raymond.hettinger at gmail.com
Sat Mar 12 03:28:54 CET 2011


Today, there was a significant check-in to the peephole optimizer that I think should be reverted:
               http://hg.python.org/cpython/rev/14205d0fee45/

The peephole optimizer pre-dated the introduction of the abstract syntax tree.  Now that we have an AST, the preferred way to implement additional optimizations is with AST manipulation, upstream from code generation.  This approach is faster and much more reliable than the more brittle approach of disassembling, analyzing, and rewriting the bytecode created by the compiler.

There should no longer be any significant changes to the existing optimizer.  It took a good deal of care to get it right in the first place.  The code is stable and has been proven successful by many years of deployment.  The nature of the peephole optimizer  is that changes to it are high risk, that the procedure is brittle, and that it is easily mucked-up in ways that are hard to detect. Accordingly, we've kept to simple conservative transformations and have assiduously avoided more complex (and interesting) optimizations.

FWIW, I've been the maintainer (as well as the original designer and implementer) of the peephole optimizer from the beginning; however, today's committer did not accept my advice to be very conservative with changes to it and to strongly prefer AST transformations instead.  Please consider reverting this change.


Raymond
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20110311/e3956b40/attachment.html>


More information about the Python-Dev mailing list