[issue11462] Peephole creates duplicate and unused constants

Raymond Hettinger report at bugs.python.org
Fri Mar 11 17:30:53 CET 2011


Raymond Hettinger <rhettinger at users.sourceforge.net> added the comment:

I'm disinclined to accept this patch.  There is only minor space savings and no actual speed-up.

When constant folding was introduced, a design decision was made to ignore the issue of orphan constants.  The rationale behind that decision still stands.

The peepholer has aspired to be very conservative and is considered a high-risk area for changes.  Since its introduction, Guido has constantly teetered on the edge of entirely ripping out the peepholer.  Right now, the stability of that code is its greatest asset and we should be reluctant to modify it.

Also, the peephole optimizer was developed before the AST branch was added to Python.  Constant folding more properly belongs at the AST level, not in the peepholer itself.  Our strategy is to move as much as possible into an AST optimizer and to stop building out the peephole optimizer.

Right now, the pattern is tokenize -> parse -> AST -> genbytecode -> peephole optimization (which disassembles the bytecode, analyzed it and rewrites it) -> final bytecode.   The correct pattern is tokenize -> parse -> AST -> optimize -> genbytecode -> peephole optimization with minimal disassembly, analysis, and opcode rewrites -> final bytecode.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue11462>
_______________________________________


More information about the Python-bugs-list mailing list