53
Welcome to the PyPy Demo Evening Laurence Tratt 2013-08-27 1/5 http://soft-dev.org/

PyPy London Demo Evening 2013

Embed Size (px)

DESCRIPTION

The slides we used at the PyPy London Demo Evening: http://morepypy.blogspot.co.uk/2013/08/preliminary-london-demo-evening-agenda.html

Citation preview

Page 1: PyPy London Demo Evening 2013

Welcome to the PyPy Demo Evening

Laurence Tratt

2013-08-27

1 / 5 http://soft-dev.org/

Page 2: PyPy London Demo Evening 2013

Why are we here?

2 / 5 http://soft-dev.org/

Page 3: PyPy London Demo Evening 2013

What do we do?

(l-r) Vasudevan, Bolz, Tratt, Barrett, Diekmann

3 / 5 http://soft-dev.org/

Page 4: PyPy London Demo Evening 2013

What do we do?

• Aim: identify important challenges in softwaredevelopment.

• Strengths: language design and implementation.

• Immediate benefits: faster VMs.

• Long-term benefits: language composition.

3 / 5 http://soft-dev.org/

Page 5: PyPy London Demo Evening 2013

What do we do?

• Aim: identify important challenges in softwaredevelopment.

• Strengths: language design and implementation.

• Immediate benefits: faster VMs.

• Long-term benefits: language composition.

3 / 5 http://soft-dev.org/

Page 6: PyPy London Demo Evening 2013

What do we do?

• Aim: identify important challenges in softwaredevelopment.

• Strengths: language design and implementation.

• Immediate benefits: faster VMs.

• Long-term benefits: language composition.

3 / 5 http://soft-dev.org/

Page 7: PyPy London Demo Evening 2013

What do we do?

• Aim: identify important challenges in softwaredevelopment.

• Strengths: language design and implementation.

• Immediate benefits: faster VMs.

• Long-term benefits: language composition.

3 / 5 http://soft-dev.org/

Page 8: PyPy London Demo Evening 2013

This evening

1 Carl Friedrich Bolz PyPy overview.

2 Lukas Diekmann Storage strategies.

3 Maciej Fijalkowski NumPy.

4 Armin Rigo Software Transactional Memory(STM).

5 Edd Barrett Language composition usingmeta-tracing.

4 / 5 http://soft-dev.org/

Page 9: PyPy London Demo Evening 2013

Can you help?

• Contributors.

• Resources.• Software Freedom Conservancy

5 / 5 http://soft-dev.org/

Page 10: PyPy London Demo Evening 2013

Can you help?

• Contributors.• Resources.

• Software Freedom Conservancy

5 / 5 http://soft-dev.org/

Page 11: PyPy London Demo Evening 2013

A Very Brief Introduction to PyPy

Carl Friedrich Bolz

PyPy Demo Evening, King’s College London,August 27, 2013

Carl Friedrich Bolz A Very Brief Introduction to PyPy

Page 12: PyPy London Demo Evening 2013

CPython is slow

CPython 1-3 orders of magnitude slower than CB

inary

Tre

es

Dhry

stone

Fannku

ch R

ed

ux

Fast

a

Knucl

eoti

de

Mand

elb

rot

Nb

od

y

Reg

exD

NA

RevC

om

p

Ric

hard

s

Sp

ect

ral N

orm

0.1

1

10

100

1000

Slo

wer

than C

, lo

wer

is b

ett

er

CJavaCpython

Carl Friedrich Bolz A Very Brief Introduction to PyPy

Page 13: PyPy London Demo Evening 2013

Reasons for Bad Performance

interpretation overheadlate bindingdispatchingboxing

Carl Friedrich Bolz A Very Brief Introduction to PyPy

Page 14: PyPy London Demo Evening 2013

Enter PyPy

a modern efficient implementation of Python

open source, MIT licensewritten in Python itself, then bootstrapped to Cuses a tracing JIT compiler to produce machine code atruntime

Carl Friedrich Bolz A Very Brief Introduction to PyPy

Page 15: PyPy London Demo Evening 2013

Enter PyPy

a modern efficient implementation of Pythonopen source, MIT licensewritten in Python itself, then bootstrapped to Cuses a tracing JIT compiler to produce machine code atruntime

Carl Friedrich Bolz A Very Brief Introduction to PyPy

Page 16: PyPy London Demo Evening 2013

Performance of PyPy

significantly faster than CPython, typically in the same order ofmagnitude than C

Bin

ary

Tre

es

Dhry

stone

Fannku

ch R

ed

ux

Fast

a

Knucl

eoti

de

Mand

elb

rot

Nb

od

y

Reg

exD

NA

RevC

om

p

Ric

hard

s

Sp

ect

ral N

orm

0.1

1

10

100

1000

Slo

wer

than C

, lo

wer

is b

ett

er

CJavaPyPyCPython

on average about 6.3 faster than CPython

Carl Friedrich Bolz A Very Brief Introduction to PyPy

Page 17: PyPy London Demo Evening 2013

Performance of PyPy

significantly faster than CPython, typically in the same order ofmagnitude than C

Bin

ary

Tre

es

Dhry

stone

Fannku

ch R

ed

ux

Fast

a

Knucl

eoti

de

Mand

elb

rot

Nb

od

y

Reg

exD

NA

RevC

om

p

Ric

hard

s

Sp

ect

ral N

orm

0.1

1

10

100

1000

Slo

wer

than C

, lo

wer

is b

ett

er

CJavaPyPyCPython

on average about 6.3 faster than CPython

Carl Friedrich Bolz A Very Brief Introduction to PyPy

Page 18: PyPy London Demo Evening 2013

Demo

Carl Friedrich Bolz A Very Brief Introduction to PyPy

Page 19: PyPy London Demo Evening 2013

Architecture

Python interpreter written in RPythonJIT-compiler automatically added via meta-tracing

Carl Friedrich Bolz A Very Brief Introduction to PyPy

Page 20: PyPy London Demo Evening 2013

Status

Python 2.7.3 support, 2.7.4 coming soonbeta-level support for Python 3.2, more coming eventuallypure Python code fully supported, please report as bug ifnot

C extension modules partially supported, if they arewell-behavedthey are slowuse cffi (a ctypes replacement) instead

Carl Friedrich Bolz A Very Brief Introduction to PyPy

Page 21: PyPy London Demo Evening 2013

Status

Python 2.7.3 support, 2.7.4 coming soonbeta-level support for Python 3.2, more coming eventuallypure Python code fully supported, please report as bug ifnotC extension modules partially supported, if they arewell-behavedthey are slowuse cffi (a ctypes replacement) instead

Carl Friedrich Bolz A Very Brief Introduction to PyPy

Page 22: PyPy London Demo Evening 2013

Questions?

PyPy is a fast JITted Python implementation(if something is not fast, please report it as a bug)open source under MIT licensehttp://pypy.org

Carl Friedrich Bolz A Very Brief Introduction to PyPy

Page 23: PyPy London Demo Evening 2013

Storage Strategies for Fast Containers

Lukas Diekmann

August, 27 2013

1 / 6 http://soft-dev.org/

Page 24: PyPy London Demo Evening 2013

Collection strategies

introduced in PyPy 1.9

optimisation of collections for certain data types

improving speed

reducing memory

2 / 6 http://soft-dev.org/

Page 25: PyPy London Demo Evening 2013

Idea

typical programs have homogeneously types collections

create optimised versions of collections for certain types

so far:

lists: ints, floats, strings/unicodesets: ints, floats, strings/unicodedicts: ints, strings/unicode

3 / 6 http://soft-dev.org/

Page 26: PyPy London Demo Evening 2013

Optimisations

collections automatically change to most efficient strategy

store elements more memory efficiently

fast elements access

4 / 6 http://soft-dev.org/

Page 27: PyPy London Demo Evening 2013

Further optimisations

collection creation and initalisation

split(d), set([1,2,3])

type based operations:

contains, difference, issubset

special strategies

RangeListStrategy: calculates elements on the fly

Tracing JIT interaction:

faster (low-level) comparisons, remove type checks

5 / 6 http://soft-dev.org/

Page 28: PyPy London Demo Evening 2013

Results

paper at OOPSLA

on average ∼18% speedup

∼6% less memory usage

more info at http://soft-dev.org/pubs/

6 / 6 http://soft-dev.org/

Page 29: PyPy London Demo Evening 2013

Numpy on PyPy

Maciej Fijałkowski

King’s College London

August 27 2013

fijal Numpy on PyPy

Page 30: PyPy London Demo Evening 2013

Goals

fully compliant numpy replacement for PyPyfast looped operationsfast vectorized operations

fijal Numpy on PyPy

Page 31: PyPy London Demo Evening 2013

Why?

fast loopingsingle language

fijal Numpy on PyPy

Page 32: PyPy London Demo Evening 2013

Model

some programs have numerical kernels that canbe written in Csome don’thttp://arxiv.org/abs/1301.1334

image manipulation demoabstraction unfriendly

fijal Numpy on PyPy

Page 33: PyPy London Demo Evening 2013

Status

fast looped operationsok vectorized operations

fijal Numpy on PyPy

Page 34: PyPy London Demo Evening 2013

Future goals

finish numpymake it fastmake it compatible with more software(matplotlib, scipy)

fijal Numpy on PyPy

Page 35: PyPy London Demo Evening 2013

Funding

about $20k leftwe likely need morebehind schedule, but not behind budget

fijal Numpy on PyPy

Page 36: PyPy London Demo Evening 2013

Q&A

Thank you!

fijal Numpy on PyPy

Page 37: PyPy London Demo Evening 2013

Software Transactional Memory on PyPy

Page 38: PyPy London Demo Evening 2013

Pseudo-Goal

I “Kill the GIL”

I GIL = Global Interpreter Lock

Page 39: PyPy London Demo Evening 2013

Real Goals

I Multi-core programming

I But reasonable multi-core programming

I Using the recent model of Transactional Memory

Page 40: PyPy London Demo Evening 2013

PyPy-STM

I An executable pypy-stm which uses internally SoftwareTransactional Memory

I Optimistically run multiple threads in parallel

I The only new feature is atomic:

with atomic:piece of code...

Page 41: PyPy London Demo Evening 2013

Example of higher-level API

def work(...):...several more calls to:

transaction.add(work, ...)...

I Starts N threads, scheduling work() calls to them

I Each work() is done in an atomic block

I Multi-core, but as if all the work() are done sequentially

Page 42: PyPy London Demo Evening 2013

Status

I Kind of working without the JIT

I Roughly three times slower (you need four cores to see benefits)

I Working on the JIT support

Page 43: PyPy London Demo Evening 2013

Q&A

I Thank you!

I Budget of $10k left, likely more needed too

Page 44: PyPy London Demo Evening 2013

Unipycation

Combining Prolog and Python

Edd Barrett

August 27, 2013

1 / 9 http://soft-dev.org/

Page 45: PyPy London Demo Evening 2013

Our Goal

The softdev team is exploring language compositions.

Ideally our compositions should be:

Easy to implement.

Transparent (as possible) to the user-programmer.

High performance.

Can meta-tracing help?

2 / 9 http://soft-dev.org/

Page 46: PyPy London Demo Evening 2013

Unipycation: A Language Composition Experiment

PyPy + Pyrolog = Unipycation

Unipycation

Both interpreters implemented in RPython.

About 600 LoC of integration code.

A few months to develop.

Languages communicate via an API.

No syntax integration yet.

3 / 9 http://soft-dev.org/

Page 47: PyPy London Demo Evening 2013

Why?

Explore composition of opposing paradigms.

Evaluate RPython as a language composition framework.

Performance/ease of development.

Composition with many realistic applications.

Example Scenario

Data acquisition by JSON/XML/Sqlite.

Easy in Python, not easy in Prolog.

Some kind of knowledge inference based upon data.

Perhaps not so easy in Python, trivial in Prolog.

Visualisation of Results.

Easy in Python, lack of library support in Prolog.

4 / 9 http://soft-dev.org/

Page 48: PyPy London Demo Evening 2013

Example

Suppose we have a directed graph (London Underground?):

a c

b

d

e

d

g

And we need to ask questions like:

Where can I get to from ’b’ via at most 4 nodes and how?

5 / 9 http://soft-dev.org/

Page 49: PyPy London Demo Evening 2013

This is Easy with Prolog

path.pl:

edge(a, c). edge(c, b). edge(c, d). edge(d, e).

edge(b, e). edge(c, f). edge(f, g). edge(e, g).

edge(g, b).

path(From , To, MaxLen , Nodes) :-

path(From , To , MaxLen , Nodes , 1).

path(Node , Node , _, [Node], _).

path(From , To, MaxLen , [From | Ahead ], Len) :-

Len < MaxLen , edge(From , Next),

Len1 is Len + 1,

path(Next , To , MaxLen , Ahead , Len1).

query: path(b, To, 4, Path).

6 / 9 http://soft-dev.org/

Page 50: PyPy London Demo Evening 2013

Example: Python → Prolog

from uni import Engine

engine = Engine.from_file ("path.pl")

paths = engine.db.path.iter

for (to , nodes) in paths("b", None , 4, None):

print ("To %s via %s" % (to, nodes))

To b via [’b’]

To e via [’b’, ’e’]

To g via [’b’, ’e’, ’g’]

To b via [’b’, ’e’, ’g’, ’b’]

Calling from Prolog to Python also possible. E.g.python:somefunc(blah)

7 / 9 http://soft-dev.org/

Page 51: PyPy London Demo Evening 2013

Performance

8 / 9 http://soft-dev.org/

Page 52: PyPy London Demo Evening 2013

In Summary

Compositions are relatively easy to implement with RPython.

We were able to implement a fairly transparent API-like interface.

Performance promising.

Further Reading

https://bitbucket.org/vext01/pypy

http://soft-dev.org/

9 / 9 http://soft-dev.org/

Page 53: PyPy London Demo Evening 2013

Looking for Python developers!

Speak to us at PyPy demo night or visit

www.pitchup.com/jobs

Python / DjangoPostgres

CeleryRedisnginx

memcacheJquery

SolrS3

Leading booking site for campsites and caravan parks, founded in 2009 by lastminute.com alumni● 65k visits / day, £6m bookings / year● 650 bookable sites● Huge market

○ 26k campsites and 300m bednights in Europe○ 600m bednights in US○ 47% more bednights than hotels (GB)○ More trips to campsites than holidays to France +

Spain combined (GB)● Team of 15, based in west London