Python in Python: the PyPy system

Armin Rigo

  • Heinrich-Heine Universit├Ąt, Germany
  • Open End AB, Sweden

March 2011

What is Python

What is Python

class Foo(object):

    def __init__(self, value):
        self.value = value

    def double(self):
        return Foo(self.value * 2)

print Foo(42).double().value
print Foo("hello").double().value

In two points

Python likes its dictionaries

d = {}
for i in [1, 2, 3, 4]:
    d[i] = i*i
print d

Python is not Java

for name in ["add", "sub", "mul"]:
    def f(x, y):
        ...
    globals()[name] = f

Python is complicated

How a + b works (simplified!):

Python is a mess

How obj.attr or obj.method() works:

What this talk is about

CPython and PyPy

CPython and PyPy

...and Jython and IronPython

What is PyPy

What is PyPy

A bit of history

What is the point of PyPy?

Speed

http://speed.pypy.org/

speed.png

And (optionally) extra features

Multi-threading

Architecture

Architecture

PyPy has two parts:

PyPy's Python interpreter

The translation toolchain

RPython is still mostly Python

RPython meta-programming

Architecture: the interpreter

Overview of the interpreter

The bytecode interpreter

The object space

Separation of levels

Example: smalllong

Example: smallint

Example: multidict

Example: mapdict

Example: mapdict

Maps

Architecture: the translation toolchain

Overview

Translation overview (1)

Translation overview (2)

Various aspects

The object model

The execution model

Garbage collection

Purpose

Overview

The GCs we have written

Old experiments

GC transformer

API example (minimark GC)

Finding the stack roots

Just-in-Time Compiler

Goal

What is a JIT

Tracing

Tracing (2)

Tracing (3)

Meta-Tracing in PyPy

Demo

Architecture of the PyPy JIT

Meta-Tracing

Optimization

Machine Code Backend

Blackhole interpreter

Bridges

More topics

Conclusion

Conclusion