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

Cesare Di Mauro cesare.di.mauro at gmail.com
Sat Mar 12 06:44:08 CET 2011


2011/3/12 Benjamin Peterson <benjamin at python.org>

> 2011/3/11 Raymond Hettinger <raymond.hettinger at gmail.com>:
> > 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.
>
> The problem is no such AST optimizer exists. It's one thing avoid
> changing old code because an improved version is in the works or
> available (say argparse in lieu of getopt) and quite another when no
> replacement code exists. At the moment, there is little reason not to
> accept progressive improvements (with sights on overall design as
> usual) to the code.
>
> IMO, Ast or not ast statically optimizing python in any meaningful way
> is a impossible task anyway. So, a better solution would be to just
>  rip the thing out.
>
> --
> Regards,
> Benjamin


It's not true. I already moved almost all peephole optimizations
(introducing others, as well) from peephole.c to
ast.c<http://code.google.com/p/wpython2/source/browse/Python/ast.c?repo=wpython11>and
compiler.c<http://code.google.com/p/wpython2/source/browse/Python/compile.c?repo=wpython11>in
WPython 1.1.

Take a look at pages 21-23 of
this<http://wpython2.googlecode.com/files/Cleanup%20and%20new%20optimizations%20in%20WPython%201.1.pdf>
.

Also, optimizations can be done not only for numbers, but even for tuples,
lists, dictionaries, and... slices (pag. 22). See pages 21-24 of
this<http://wpython2.googlecode.com/files/Beyond%20Bytecode%20-%20A%20Wordcode-based%20Python.pdf>
.

Cesare
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20110312/17cc4ecd/attachment.html>


More information about the Python-Dev mailing list