Slide 1

Slide 1 text

PyPy Armin Rigo PyCon ZA 2012 October 4, 2012 Armin Rigo (PyCon ZA 2012) PyPy in Production October 4, 2012 1 / 15

Slide 2

Slide 2 text

PyPy is... Another Python interpreter with a JIT compiler Armin Rigo (PyCon ZA 2012) PyPy in Production October 4, 2012 1 / 15

Slide 3

Slide 3 text

PyPy was... Around since 2003 (advertised as) production ready since December 2010 I release 1.4 Funding I EU FP6 programme I Eurostars programme I donations I ... Armin Rigo (PyCon ZA 2012) PyPy in Production October 4, 2012 2 / 15

Slide 4

Slide 4 text

PyPy 1.9: current status Faster I 1.7x than 1.5 (Summer 2011) I 2.2x than 1.4 (December 2010) I 5.5x than CPython Implements Python 2.7.3 Many more “PyPy-friendly” programs than before Packaging I Debian, Ubuntu, Fedora, Homebrew, Gentoo, ArchLinux, ... I Windows (32bit only), OS X C extension compatibility I runs (big part of) PyOpenSSL and lxml Armin Rigo (PyCon ZA 2012) PyPy in Production October 4, 2012 3 / 15

Slide 5

Slide 5 text

PyPy organization Part of SFC -- Software Freedom Conservancy I Bradley successfully fighting U.S. bureaucracy I we are happy about it Funding model I py3k, numpy, STM I more than 100’000$ in donations I from individuals, large companies and the PSF Armin Rigo (PyCon ZA 2012) PyPy in Production October 4, 2012 4 / 15

Slide 6

Slide 6 text

PyPy’s JIT compiler Removes abstraction Almost never gives up x86-32, x86-64, ARMv7, (POWER64) (Works with other languages) Armin Rigo (PyCon ZA 2012) PyPy in Production October 4, 2012 5 / 15

Slide 7

Slide 7 text

Real world applications Positive feedback http://speed.pypy.org/ Armin Rigo (PyCon ZA 2012) PyPy in Production October 4, 2012 6 / 15

Slide 8

Slide 8 text

py3k py3k branch in mercurial I developed in parallel I Python 3 written in Python 2 Focus on correctness Dropped some interpreter optimizations for now First 90% done, remaining 90% not done Majority of the funds by Google Armin Rigo (PyCon ZA 2012) PyPy in Production October 4, 2012 7 / 15

Slide 9

Slide 9 text

NumPy progress going slowly multi dimensional arrays, broadcasting, fancy indexing all dtypes, except complex, strings and objects good results for performance Armin Rigo (PyCon ZA 2012) PyPy in Production October 4, 2012 8 / 15

Slide 10

Slide 10 text

STM Software Transactional Memory “Remove the GIL” But also, new models (better than threads) Armin Rigo (PyCon ZA 2012) PyPy in Production October 4, 2012 9 / 15

Slide 11

Slide 11 text

Calling C Armin Rigo (PyCon ZA 2012) PyPy in Production October 4, 2012 10 / 15

Slide 12

Slide 12 text

Calling C landscape CPython C extensions SWIG, SIP, wrapper generators ctypes Cython CFFI (our new thing) Armin Rigo (PyCon ZA 2012) PyPy in Production October 4, 2012 11 / 15

Slide 13

Slide 13 text

CFFI Example >>> from cffi import FFI >>> ffi = FFI() >>> ffi.cdef(""" ... int printf(const char *format, ...); ... """) >>> C = ffi.dlopen(None) >>> arg = ffi.new("char[]", "world") >>> C.printf("hi there, %s!\n", arg) hi there, world! Armin Rigo (PyCon ZA 2012) PyPy in Production October 4, 2012 12 / 15

Slide 14

Slide 14 text

CFFI Many more examples Including macro calls and most subtleties of C http://cffi.readthedocs.org Armin Rigo (PyCon ZA 2012) PyPy in Production October 4, 2012 13 / 15

Slide 15

Slide 15 text

STM Armin Rigo (PyCon ZA 2012) PyPy in Production October 4, 2012 14 / 15

Slide 16

Slide 16 text

Conclusion Try out PyPy on real code http://pypy.org/ Thank you! Armin Rigo (PyCon ZA 2012) PyPy in Production October 4, 2012 15 / 15