PyPy 1.0: JIT compilers for free and more

Carl Friedrich Bolz cfbolz at gmx.de
Wed Mar 28 17:41:33 EDT 2007


Kay Schluehr wrote:
 > Nice to read that things are going on. I've still a PyPy 0.7 version
 > on my notebook. I guess I will upgrade :)
 >
 > A somewhat unrelated question. With Py3K Python gets optional type
 > annotations. Are you already architecting an annotation handler that
 > can process these annotations? This feature is somewhat competitive to
 > all the complicated type inference and jitting you have been worked
 > out so I don't know how it fits well into the current PyPy
 > architecture?

I don't see at all why type annotations are competitive to the type
inference that PyPy's translation toolchain is doing. The type inference
of PyPy is an artefact of the way we are implementing our interpreter
(namely in RPython). You also wouldn't say that the static typing of C
is competitive to type annotations because CPython is written in C,
right?

The JIT (which is completely independent from our type inference engine)
will hopefully deal well with the eventual addition of type annotations
(it's not clear to me how soon we will start supporting Py3k features,
we are not even fully supporting Python 2.5 yet). Since the JIT is
automatically generated out of the Python interpreter it should deal
with any sort of language changes rather well. Whether that is true in
practice remains to be seen, but this is one of the reason why PyPy was
started in the first place.

Also, I fail to see how type annotations can have a huge speed-advantage
versus what our JIT and Psyco are doing. Imagine you have a function
that is nicely algorithmic, takes only integers as arguments and only
does some calculations with them. If you have a Psyco-like scheme, the
JIT will note that you are using it mostly with ints, generate
relatively efficient assembly for the whole function (at least after it
has been called several times). If you call that functions, the
arguments are checked whether they are integers and then the fast
assembly code is used without any further type checks. How can you
improve on this with type annotations? If the type annotations say that
your arguments have to be ints, you _still_ have to check whether this
is true. So it is not faster than what Psyco is doing and has the
disadvantage that it only works with ints -- good bye, duck typing.
Psyco on the other hand will be perfectly happy with you using a custom
class that looks mostly like an int and generate assembly optimized for
this situation.

Cheers,

Carl Friedrich Bolz



More information about the Python-list mailing list