Slide 1

Slide 1 text

PyPy meets Python 3 and Numpy (and other What’s New topics) Armin Rigo PyConZA 2017 October 2017

Slide 2

Slide 2 text

What’s New In PyPy 1. Python 3.5 2. Numpy, Cython, Pandas, ... 3. pypy-stm? 4. RevDB: reverse debugging 5. Others...

Slide 3

Slide 3 text

What is PyPy PyPy is another implementation of Python Mostly, drop-in replacement Supports Python 2.7, and almost Python 3.5 Comes with a JIT, good performance

Slide 4

Slide 4 text

PyPy 3.5

Slide 5

Slide 5 text

PyPy 3.5 Python 3.5 support released in gamma as stable (and mostly as fast) as PyPy 2.7, same JIT/GC/etc. what could be wrong is a few details everywhere please try it and report issues! Thanks to Mozilla for funding this work!

Slide 6

Slide 6 text

PyPy 3.5 Async HTTP benchmarks:

Slide 7

Slide 7 text

PyPy 3.5 status Roughly complete 3.5 support (plus f-strings!) Reasonably good performance Tested mostly on Linux so far First "final" to be released very soon Python 3.6 to follow

Slide 8

Slide 8 text

Scientific stack

Slide 9

Slide 9 text

Scientific stack Numpy or Numpypy? Numpy = the standard numpy library Numpypy = our own partial reimplementation

Slide 10

Slide 10 text

Scientific stack Numpy or Numpypy? Numpy = the standard numpy library (use this) Numpypy = our own partial reimplementation (deprecated)

Slide 11

Slide 11 text

Scientific stack Numpy works (99.9%) On both PyPy 2.7 and PyPy 3.5 The rest of the scientific stack mostly works too (Jupyter, Matplotlib, Pandas, etc.)

Slide 12

Slide 12 text

Cython, cpyext Cython mostly works Actually, any CPython C extension module mostly works Thanks to cpyext, our CPython C API emulation layer

Slide 13

Slide 13 text

Performance? Numpy/Pandas/etc. are all slow-ish at the Python-C boundary Less so than last year but still Complex algorithms written inside Numpy in C or Fortran have the same speed, of course lots of ndarray[index] => slow one call to numpy.linalg.eig() => fast speed hack: p = ffi.cast("double *", ffi.from_buffer(ndarray))

Slide 14

Slide 14 text

Performance? We have plans to improve Funding help welcome For now: try it out on your own code and see

Slide 15

Slide 15 text

Software Transactional Memory

Slide 16

Slide 16 text

Software Transactional Memory pypy-stm: getting rid of the Global Interpreter Lock

Slide 17

Slide 17 text

Software Transactional Memory ...unfortunately, this approach does not seem to work :-(

Slide 18

Slide 18 text

Software Transactional Memory Unstable performance: "Conflicts" between threads are hard to find Fix one conflict, usually only to uncover the next one As long as there is one, performance is bad You may fix enough to get good performance... but: Continue developing the program, and you’ll often reintroduce conflicts (Also, hard to test for, reliably)

Slide 19

Slide 19 text

PyPy-nogil? Another possibility: a GIL-free but non-STM PyPy Large amount of work, large maintenance burden Lots of hype, but we would need serious commercial funding and backing

Slide 20

Slide 20 text

Reverse Debugger

Slide 21

Slide 21 text

Reverse Debugger RevDB: The essential tool you need once a year

Slide 22

Slide 22 text

Reverse Debugger Debugger with the ability to go forward and backward in time Watchpoints to know when a value changes, while going in either direction http://bitbucket.org/pypy/revdb

Slide 23

Slide 23 text

Others

Slide 24

Slide 24 text

JIT improvements Reductions in the warm-up time Consumes less memory, too

Slide 25

Slide 25 text

VMProf A good high-performance profiler for Python code pip install vmprof Works on CPython and on PyPy The PyPy version shows the machine code generated by the JIT

Slide 26

Slide 26 text

CFFI improvements CFFI: calling C from Python or the other way around Works identically on CPython and on PyPy Biggest improvement of last year is embedding Use CFFI to embed Python inside another program---much easier than with the CPython C API, and works identically on CPython or PyPy too

Slide 27

Slide 27 text

Next year?

Slide 28

Slide 28 text

Next year? Polish PyPy 3.5 / 3.6 Polish Numpy and the scientific stack Port RevDB to PyPy 3.5 Better memory profiling

Slide 29

Slide 29 text

Question & answers Polish PyPy 3.5 / 3.6 Polish Numpy and the scientific stack Port RevDB to PyPy 3.5 Better memory profiling Thank you! http://pypy.org/