by Alex Gaynor, Maciej Fijalkowski and Armin Rigo
One of the goals of PyPy is to make existing Python code faster, however an even broader goal was to make it possible to write things in Python that previous would needed to be written in C or other low-level language. This talk will show examples of this, and describe how they represent the tremendous progress PyPy has made, and what it means for people looking to use PyPy.
In this talk we'll talk about PyPy's present status and for what kinds of applications it might be useful. We'll also show examples of things that are possible with PyPy that were impossible to do with Python before, like real time video processing done in pure python. Our objective with each of the examples will be to highlight the type of work that is sped up and why this represents both a boon for existing Python programmers, as well as an opportunity for Python to expand to new audiences.
We'll also explain a bit PyPy's accomplishements in the passing year that make all of this possible, current status, its goals and the near future.
The Python community is abuzz about the major speed gains PyPy can offer pure Python code. But how does PyPy JIT actually work? This talk will discuss how the PyPy JIT is implemented. It will include descriptions of the tracing, optimization, and assembly generation phases. I will demonstrate each step with a example loop.
Strictly speaking, PyPy doesn't have a JIT; it has a JIT generator. I will describe how the JIT is generated during the translation of the interpreter as well as the advantages of the meta-JIT method.
Next, we'll explore tracing, in which the JIT records operations in a hot loop. I'll introduce the meta interpreter and the JIT IR (intermediate representation).
Optimizations are the next step of JITing. The focus will be on the most important optimizations for dynamic languages: virtuals and virtualizables. However, PyPy also includes the standard set of compiler peephole optimizations, like strength reduction, and well as some more complicated loop optimizations, like constant hoisting.
The final topic will be assembly generation. We'll see register allocation and how specific high-level Python operations are compiled down to tight x86 instructions.
Time permitting, additional topics may include how the garbage collector is integrated with the JIT and how the JIT bails back to the interpreter when a guard fails.
Along the way, I will demonstrate how each phase of JITing acts on an example Python loop. This will also allow me to introduce the jitviewer, a program to view how PyPy is compiling your loops.