Fast Python? Don’t Bother - Russel · Fast Python? Don’t Bother Russel Winder...

44
Copyright © 2016 Russel Winder 1 Fast Python? Don’t Bother Russel Winder [email protected] https://www.russel.org.uk @russel_winder

Transcript of Fast Python? Don’t Bother - Russel · Fast Python? Don’t Bother Russel Winder...

Page 1: Fast Python? Don’t Bother - Russel · Fast Python? Don’t Bother Russel Winder russel@winder.org.uk @russel_winder. Author: Russel Winder Created Date: 9/17/2016 3:42:45 PM ...

Copyright © 2016 Russel Winder 1

Fast Python? Don’t Bother

Russel Winder

[email protected]://www.russel.org.uk

@russel_winder

Page 2: Fast Python? Don’t Bother - Russel · Fast Python? Don’t Bother Russel Winder russel@winder.org.uk @russel_winder. Author: Russel Winder Created Date: 9/17/2016 3:42:45 PM ...

Copyright © 2016 Russel Winder 2

There is a rumour I only come to PyCon UK to talk about languages other than Python…

Page 3: Fast Python? Don’t Bother - Russel · Fast Python? Don’t Bother Russel Winder russel@winder.org.uk @russel_winder. Author: Russel Winder Created Date: 9/17/2016 3:42:45 PM ...

Copyright © 2016 Russel Winder 3

…this is not true…

Page 4: Fast Python? Don’t Bother - Russel · Fast Python? Don’t Bother Russel Winder russel@winder.org.uk @russel_winder. Author: Russel Winder Created Date: 9/17/2016 3:42:45 PM ...

Copyright © 2016 Russel Winder 4

…well not entirely.

Page 5: Fast Python? Don’t Bother - Russel · Fast Python? Don’t Bother Russel Winder russel@winder.org.uk @russel_winder. Author: Russel Winder Created Date: 9/17/2016 3:42:45 PM ...

Copyright © 2016 Russel Winder 5

A gentle rant, but…

Page 6: Fast Python? Don’t Bother - Russel · Fast Python? Don’t Bother Russel Winder russel@winder.org.uk @russel_winder. Author: Russel Winder Created Date: 9/17/2016 3:42:45 PM ...

Copyright © 2016 Russel Winder 6

…a bit of a rant nonetheless.

Page 7: Fast Python? Don’t Bother - Russel · Fast Python? Don’t Bother Russel Winder russel@winder.org.uk @russel_winder. Author: Russel Winder Created Date: 9/17/2016 3:42:45 PM ...

Copyright © 2016 Russel Winder 7

Python is…● A dynamically typed (or not) language.

● Quite popular, in data science, and data visualisation.

● Quite popular for sys. admin.

● Quite popular for Web-y stuff.

● Having it’s development driven by IDEs.

Type signatures.

Page 8: Fast Python? Don’t Bother - Russel · Fast Python? Don’t Bother Russel Winder russel@winder.org.uk @russel_winder. Author: Russel Winder Created Date: 9/17/2016 3:42:45 PM ...

Copyright © 2016 Russel Winder 8

Slow

Page 9: Fast Python? Don’t Bother - Russel · Fast Python? Don’t Bother Russel Winder russel@winder.org.uk @russel_winder. Author: Russel Winder Created Date: 9/17/2016 3:42:45 PM ...

Copyright © 2016 Russel Winder 9

Python is not…● A high performance computational language.

● A language in which you can write parallel programs.

Page 10: Fast Python? Don’t Bother - Russel · Fast Python? Don’t Bother Russel Winder russel@winder.org.uk @russel_winder. Author: Russel Winder Created Date: 9/17/2016 3:42:45 PM ...

Copyright © 2016 Russel Winder 10

Page 11: Fast Python? Don’t Bother - Russel · Fast Python? Don’t Bother Russel Winder russel@winder.org.uk @russel_winder. Author: Russel Winder Created Date: 9/17/2016 3:42:45 PM ...

Copyright © 2016 Russel Winder 11

Maybe the GIL is a good thing,

it stops us using Python when we shouldn’t.

Page 12: Fast Python? Don’t Bother - Russel · Fast Python? Don’t Bother Russel Winder russel@winder.org.uk @russel_winder. Author: Russel Winder Created Date: 9/17/2016 3:42:45 PM ...

Copyright © 2016 Russel Winder 12

Why?

Page 13: Fast Python? Don’t Bother - Russel · Fast Python? Don’t Bother Russel Winder russel@winder.org.uk @russel_winder. Author: Russel Winder Created Date: 9/17/2016 3:42:45 PM ...

Copyright © 2016 Russel Winder 13

Parallelism

Page 14: Fast Python? Don’t Bother - Russel · Fast Python? Don’t Bother Russel Winder russel@winder.org.uk @russel_winder. Author: Russel Winder Created Date: 9/17/2016 3:42:45 PM ...

Copyright © 2016 Russel Winder 14

So how to do computation?● Cython

● Numba

● NumPy

Page 15: Fast Python? Don’t Bother - Russel · Fast Python? Don’t Bother Russel Winder russel@winder.org.uk @russel_winder. Author: Russel Winder Created Date: 9/17/2016 3:42:45 PM ...

Copyright © 2016 Russel Winder 15

Cython● Write Python and annotate the code to make it appear

like C so it is actually C by source-to-source translation.

Hats off to Pyrex.

Page 16: Fast Python? Don’t Bother - Russel · Fast Python? Don’t Bother Russel Winder russel@winder.org.uk @russel_winder. Author: Russel Winder Created Date: 9/17/2016 3:42:45 PM ...

Copyright © 2016 Russel Winder 16

Why not just write C if you want to write C?

Page 17: Fast Python? Don’t Bother - Russel · Fast Python? Don’t Bother Russel Winder russel@winder.org.uk @russel_winder. Author: Russel Winder Created Date: 9/17/2016 3:42:45 PM ...

Copyright © 2016 Russel Winder 17

Because C is a programming language for writing operating systems, not applications?

Page 18: Fast Python? Don’t Bother - Russel · Fast Python? Don’t Bother Russel Winder russel@winder.org.uk @russel_winder. Author: Russel Winder Created Date: 9/17/2016 3:42:45 PM ...

Copyright © 2016 Russel Winder 18

What we want is Fortran or even FORTRAN.

Page 19: Fast Python? Don’t Bother - Russel · Fast Python? Don’t Bother Russel Winder russel@winder.org.uk @russel_winder. Author: Russel Winder Created Date: 9/17/2016 3:42:45 PM ...

Copyright © 2016 Russel Winder 19

Or not.

Page 20: Fast Python? Don’t Bother - Russel · Fast Python? Don’t Bother Russel Winder russel@winder.org.uk @russel_winder. Author: Russel Winder Created Date: 9/17/2016 3:42:45 PM ...

Copyright © 2016 Russel Winder 20

Numba● Write Python code and decorate with decorator so as to

perform non-Python translation via LLVM to native code.

Page 21: Fast Python? Don’t Bother - Russel · Fast Python? Don’t Bother Russel Winder russel@winder.org.uk @russel_winder. Author: Russel Winder Created Date: 9/17/2016 3:42:45 PM ...

Copyright © 2016 Russel Winder 21

Does Python really havenative code semantics?

Page 22: Fast Python? Don’t Bother - Russel · Fast Python? Don’t Bother Russel Winder russel@winder.org.uk @russel_winder. Author: Russel Winder Created Date: 9/17/2016 3:42:45 PM ...

Copyright © 2016 Russel Winder 22

Does RPython really havenative code semantics?

Page 23: Fast Python? Don’t Bother - Russel · Fast Python? Don’t Bother Russel Winder russel@winder.org.uk @russel_winder. Author: Russel Winder Created Date: 9/17/2016 3:42:45 PM ...

Copyright © 2016 Russel Winder 23

No

Page 24: Fast Python? Don’t Bother - Russel · Fast Python? Don’t Bother Russel Winder russel@winder.org.uk @russel_winder. Author: Russel Winder Created Date: 9/17/2016 3:42:45 PM ...

Copyright © 2016 Russel Winder 24

NumPy● And the whole SciPy, Pandas, etc. kit and caboodle.

● A C subsystem, providing opaque data types and operations well integrated with Python as an API.

Page 25: Fast Python? Don’t Bother - Russel · Fast Python? Don’t Bother Russel Winder russel@winder.org.uk @russel_winder. Author: Russel Winder Created Date: 9/17/2016 3:42:45 PM ...

Copyright © 2016 Russel Winder 25

It’s just a C system with a nice API.

Lots of niceness to the API.

Page 26: Fast Python? Don’t Bother - Russel · Fast Python? Don’t Bother Russel Winder russel@winder.org.uk @russel_winder. Author: Russel Winder Created Date: 9/17/2016 3:42:45 PM ...

Copyright © 2016 Russel Winder 26

Is C good enough for computation

in the modern era?

Page 27: Fast Python? Don’t Bother - Russel · Fast Python? Don’t Bother Russel Winder russel@winder.org.uk @russel_winder. Author: Russel Winder Created Date: 9/17/2016 3:42:45 PM ...

Copyright © 2016 Russel Winder 27

No

Page 28: Fast Python? Don’t Bother - Russel · Fast Python? Don’t Bother Russel Winder russel@winder.org.uk @russel_winder. Author: Russel Winder Created Date: 9/17/2016 3:42:45 PM ...

Copyright © 2016 Russel Winder 28

Why?

Page 29: Fast Python? Don’t Bother - Russel · Fast Python? Don’t Bother Russel Winder russel@winder.org.uk @russel_winder. Author: Russel Winder Created Date: 9/17/2016 3:42:45 PM ...

Copyright © 2016 Russel Winder 29

Parallelism

Page 30: Fast Python? Don’t Bother - Russel · Fast Python? Don’t Bother Russel Winder russel@winder.org.uk @russel_winder. Author: Russel Winder Created Date: 9/17/2016 3:42:45 PM ...

Copyright © 2016 Russel Winder 30

Multi-multicore processors

GPGPU

Page 31: Fast Python? Don’t Bother - Russel · Fast Python? Don’t Bother Russel Winder russel@winder.org.uk @russel_winder. Author: Russel Winder Created Date: 9/17/2016 3:42:45 PM ...

Copyright © 2016 Russel Winder 31

OpenCL

Vulkan

CUDA

Page 32: Fast Python? Don’t Bother - Russel · Fast Python? Don’t Bother Russel Winder russel@winder.org.uk @russel_winder. Author: Russel Winder Created Date: 9/17/2016 3:42:45 PM ...

Copyright © 2016 Russel Winder 32

Actors

CSP

Dataflow

Data Parallelism

Page 33: Fast Python? Don’t Bother - Russel · Fast Python? Don’t Bother Russel Winder russel@winder.org.uk @russel_winder. Author: Russel Winder Created Date: 9/17/2016 3:42:45 PM ...

Copyright © 2016 Russel Winder 33

Parallel Processing● Threads and thread pools:

– C – but very low level.

– C++ – better than C.

– Java: Akka, Quasar, Hadoop, Apache Spark, GPars.

– D – actors and data parallelism.

● Partitioned Global Address Space (PGAS):– Chapel

– X10

There are man, many more:Pony, Nim, etc.

Page 34: Fast Python? Don’t Bother - Russel · Fast Python? Don’t Bother Russel Winder russel@winder.org.uk @russel_winder. Author: Russel Winder Created Date: 9/17/2016 3:42:45 PM ...

Copyright © 2016 Russel Winder 34

Where does Python fit in?

Page 35: Fast Python? Don’t Bother - Russel · Fast Python? Don’t Bother Russel Winder russel@winder.org.uk @russel_winder. Author: Russel Winder Created Date: 9/17/2016 3:42:45 PM ...

Copyright © 2016 Russel Winder 35

It doesn’t for the computation…

Page 36: Fast Python? Don’t Bother - Russel · Fast Python? Don’t Bother Russel Winder russel@winder.org.uk @russel_winder. Author: Russel Winder Created Date: 9/17/2016 3:42:45 PM ...

Copyright © 2016 Russel Winder 36

…but there is a way forward:

Page 37: Fast Python? Don’t Bother - Russel · Fast Python? Don’t Bother Russel Winder russel@winder.org.uk @russel_winder. Author: Russel Winder Created Date: 9/17/2016 3:42:45 PM ...

Copyright © 2016 Russel Winder 37

Microservices Architecture

Page 38: Fast Python? Don’t Bother - Russel · Fast Python? Don’t Bother Russel Winder russel@winder.org.uk @russel_winder. Author: Russel Winder Created Date: 9/17/2016 3:42:45 PM ...

Copyright © 2016 Russel Winder 38

Processes communicating over a network.

Processes on same computer communicating using inter-process communication.

Page 39: Fast Python? Don’t Bother - Russel · Fast Python? Don’t Bother Russel Winder russel@winder.org.uk @russel_winder. Author: Russel Winder Created Date: 9/17/2016 3:42:45 PM ...

Copyright © 2016 Russel Winder 39

Processes communicating is the only way pure Python code can create parallelism so it must be Pythonic.

Page 40: Fast Python? Don’t Bother - Russel · Fast Python? Don’t Bother Russel Winder russel@winder.org.uk @russel_winder. Author: Russel Winder Created Date: 9/17/2016 3:42:45 PM ...

Copyright © 2016 Russel Winder 40

Intermix Python processes with non-Python ones.

Page 41: Fast Python? Don’t Bother - Russel · Fast Python? Don’t Bother Russel Winder russel@winder.org.uk @russel_winder. Author: Russel Winder Created Date: 9/17/2016 3:42:45 PM ...

Copyright © 2016 Russel Winder 41

Intermix:● Python ● C

● C++

● Rust

● D

● Chapel

Page 42: Fast Python? Don’t Bother - Russel · Fast Python? Don’t Bother Russel Winder russel@winder.org.uk @russel_winder. Author: Russel Winder Created Date: 9/17/2016 3:42:45 PM ...

Copyright © 2016 Russel Winder 42

Peek at D and Chapel.

https://github.com/russel/Pi_Quadrature

Page 43: Fast Python? Don’t Bother - Russel · Fast Python? Don’t Bother Russel Winder russel@winder.org.uk @russel_winder. Author: Russel Winder Created Date: 9/17/2016 3:42:45 PM ...

Copyright © 2016 Russel Winder 43

Follow Up…

Short hands-on workshop:

Monday 2016-09-19T14:30+01:00Room A

Page 44: Fast Python? Don’t Bother - Russel · Fast Python? Don’t Bother Russel Winder russel@winder.org.uk @russel_winder. Author: Russel Winder Created Date: 9/17/2016 3:42:45 PM ...

Copyright © 2016 Russel Winder 44

Fast Python? Don’t Bother

Russel Winder

[email protected]://www.russel.org.uk

@russel_winder