[pypy-dev] python bytecode optimization.

Amaury Forgeot d'Arc amauryfa at gmail.com
Mon Jan 21 12:24:23 CET 2013


Hi,

2013/1/19 Robert Zaremba <robert.zaremba at zoho.com>

> Hi,
> I really like the work you do and try to support by trying to make all my
> python project runing under PyPy, being PyPy  proponent, convince others to
> PyPy, putting some founding, talk about PyPy.
>

Thank you, and good luck!


> I try to learn PyPy architecture and someday contribute (if I got more free
> time). I know that PyPy bind a lot of optimizations.
> My question is how it looks from bytecode interpretation (so without
> JITing)?
> I learned about AST optimizers for CPython (like
> https://bitbucket.org/haypo/astoptimizer, hotpy).
> Does PyPy bytcode interpreter implements some of them on bytecode level? I
> know that PyPy produce similar bytecode as CPython
> (http://doc.pypy.org/en/latest/architecture.html#the-python-interpreter),
> so I
> guess PyPy doesn't introduce such optymalizations. But maybe on some other
> interpreter level?
>

IIRC, PyPy used an AST compiler before CPython did.

Most (all?) code optimizations are already performed at the AST level, see
https://bitbucket.org/pypy/pypy/src/default/pypy/interpreter/astcompiler/optimize.py
Cpython on the other hand optimizes the bytecode itself
(in Python/peephole.c)

PyPy fail on some astoptimizer tests. It is pure Python, but manipulates
> AST.
> I make a little introspection and i think, the reason is due to small
> bytecode
> differences? The AST (resulted and expected) looks similar, by the PyPy
> one is
> simpler.
>

astoptimizer is similar to the one built in PyPy, but much more aggressive,
and can sometimes change semantics.
For example, it assume that builtin functions are not shadowed.
It can be interesting in many cases, but will produce different behavior in
some cases.

Most of the failures in astoptimize tests are shallow: When compiling from
an ast tree,
PyPy will optimize it and modify it in-place (CPython doesn't)
I modified a bit these tests to add a call to compile() on the ast used for
comparison,
and most tests pass now.

They found a crash too, around the empty set(); I fixed it in my workspace,
will try to submit it tonight.

-- 
Amaury Forgeot d'Arc
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pypy-dev/attachments/20130121/1b59e804/attachment.html>


More information about the pypy-dev mailing list