Mind Bending

In continuation to the series of articles PyCon2011 Highlights, today I won’t just suggest but insist with you to watch this great talk by Maciej Fijałkowski and Alex Gaynor, about the Python’s Virtual Machine called PyPy. I always wondered how PyPy (which is written in Python) can be faster than CPython (which is written in C). This talk not only clarified this question of mine but made me very curious about the subject, which resulted in a little research to better understand PyPy and JIT.

For those who were lost during the lecture, here’s a brief explanation on how PyPy and JIT work.

What is PyPy?

PyPy is an OpenSource Project, active for about eight years, which aims to create a new Python interpreter. His stable version has a 99.99% compatibility (more information about incompatibilities are available in the official website) and offers a significant performance gain without changing the language. To ensure the highest level of compatibility, PyPy’s unit tests have around 150 thousand lines of code. To get a better idea of the performance gain offered by PyPy, simply visit the site PyPy Speed Center, all graphs are normalized by the CPython response time.

PyPy Logo

Currently PyPy (in its version 1.6) is Python 2.7.1 compatible and is available for x86 and x86_64 platforms here. According to his official web page, a version for ARM platform is being developed.

But how can they be faster?

Every PyPy effort is about "making your computer work less", through the use of JIT, an acronym that stands for Just-In-Time. Unlike a common virtual machine, a machine that uses JIT performs a translation of the bytecode to native machine code during its execution.

The main idea of a JIT virtual machine is to combine the advantages of the virtual machines concept (that use bytecode to ensure portability) and traditional compilation (which converts the source code directly to machine code). Also the compiler make some analysis on the source code and make all possible optimizations, obtaining a set of bytecodes optimized and semantically equivalent to the original source program.

Magnun

Magnun

Graduated in Telecommunication Engineering, but currently working with GNU/Linux infrastructure and in the spare time I'm an Open Source programmer (Python and C), a drawer and author in the Mind Bending Blog.


Comments

comments powered by Disqus