SlideShare a Scribd company logo
Pythonic doesn't mean slow!
Ronan Lamy
About meAbout me
PyPy core dev
Python consultant and freelance developer
Contact:
Ronan.Lamy@gmail.com
@ronanlamy
We love PythonWe love Python
Why Python?Why Python?
Easy to learn
Easy to read
Simplicity
Community
Many libraries
Technical reasonsTechnical reasons
"Readability counts"
Uniform object model
Simple & expressive APIs
Powerful abstractions
Modularity/extensibility
What about performance?What about performance?
Who cares about performance?Who cares about performance?
Workaround #1: Using high-performance librariesWorkaround #1: Using high-performance libraries
GoodGood
Feels like Python
Also includes domain knowledge
Actually the default option
BadBad
Somewhat slow
Limited customisation options
Can only use what's implemented
Workaround #2: Rewrite in CWorkaround #2: Rewrite in C
Cython
C + cf
Write a C extension 😱
Numba
...
GoodGood
Fast
Developer has full control
BadBad
Different, less convenient, language
Unoptimised parts can become signi cant again
Python/C boundary is a bottleneck
C implementations cause bad APIsC implementations cause bad APIs
In [ ]: import numpy
class myarray(numpy.ndarray):
pass
In [ ]: import pandas
help(pandas.read_csv)
Fast vs PythonicFast vs Pythonic
PyPyPyPy
Fast and compliant implementation of Python
PyPy v7.2 released on 14 October
Supports 2.7 and 3.6
JIT compiler
GC tuned for Python
PyPy - DemoPyPy - Demo
In [2]: %%time
class Quantity:
def __init__(self, value, unit):
self.value = value
self.unit = unit
def __add__(self, other):
if isinstance(other, Quantity):
if other.unit != self.unit: raise ValueError("units must match")
else: return Quantity(self.value + other.value, self.unit)
else: return NotImplemented
def __str__(self):
return f"{self.value} {self.unit}"
def compute(n):
total = Quantity(0, 'm')
increment = Quantity(1., 'm')
for i in range(n):
total += increment
return total
N = 1_000_000_000
print(compute(N))
3.6.9 (default, Jul 3 2019, 15:36:16)
[GCC 5.4.0 20160609]
1000000000.0 m
CPU times: user 29min 4s, sys: 112 ms, total: 29min 4s
Wall time: 29min 4s
How fast is PyPy?How fast is PyPy?
It dependsIt depends
Up to 1000x faster than CPython in extreme cases
Up to 50x in more realistic cases
2-5x on "typical" applications
Can be slower (short scripts, tests, ...)
C extension supportC extension support
cpyext = "Python.h for PyPy"
numpy, scipy, pandas, scikit-learn, lxml, ...
Cython + most extensions written in Cython
'pip install' works
Wheels available at
https://github.com/antocuni/pypy-wheels
PyPy qualitiesPyPy qualities
Make Pythonic code fast
Abstractions for free
Make Python a 1st-class language for HPC
PyPy issuesPyPy issues
Lags behind CPython
Implementation details are different
Need to understand GC and JIT to get best performance
No conda
Small community
cpyext issuescpyext issues
CPython API is huge
Grey areas
Patchy library support
High overhead
HPyHPy
New C API
No refcounting
Replace PyObject* with opaque handles
Don't expose implementation details
https://github.com/pyhandle/hpy (https://github.com/pyhandle/hpy)
HPy: plansHPy: plans
In one yearIn one year
CPython: implemented on top of existing API
PyPy: much more ef cient than cpyext
Used by Cython
Long-termLong-term
Replaces current C-API
Used by all relevant implementations
CPython free to experiment and modify internals
SummarySummary
PyPy makes pure-Python fast
Compatible with PyData ecosystem
Computing in Python becomes viable
Complements traditional approaches to performance
ContactContact
IRC: #pypy on Freenode IRC
pypy-dev @ python.org
Questions?
http://pypy.org (http://pypy.org)
The endThe end

More Related Content

PPTX
PDF
Writing Fast Code - PyCon HK 2015
PPT
a quick Introduction to PyPy
ZIP
An Introduction to PyPy
PDF
PyPy
PPTX
Python 101 for the .NET Developer
PPTX
Python vs c++ ppt
PDF
Python for Science and Engineering: a presentation to A*STAR and the Singapor...
Writing Fast Code - PyCon HK 2015
a quick Introduction to PyPy
An Introduction to PyPy
PyPy
Python 101 for the .NET Developer
Python vs c++ ppt
Python for Science and Engineering: a presentation to A*STAR and the Singapor...

What's hot (20)

PDF
UNSW Australia Robocup Recap Hefei 2015
PDF
Raspberry using Python Session 1
PPTX
Top 10 python ide
PPTX
Python programming | Fundamentals of Python programming
PPT
Py Con 2009 Pumping Iron Into Python
PDF
Getting started with Linux and Python by Caffe
PPTX
First python project
PDF
Python Scripting Tutorial for Beginners | Python Tutorial | Python Training |...
PDF
Introduction to python
PPT
Python Introduction
PDF
Raspberry using Python Session 3
PDF
gRPC 프레임워크를 만들며 알아보는 파이썬 - 파이콘2020
PDF
Mp24: Python in gaming industry
PDF
平行化你的工作 part1
PPT
Porting To Symbian
PPTX
Machine Learning on Your Hand - Introduction to Tensorflow Lite Preview
PDF
Number of Computer Languages = 3
PDF
PyPy London Demo Evening 2013
PDF
Python 3.5: An agile, general-purpose development language.
PPTX
Top python interview question and answer
UNSW Australia Robocup Recap Hefei 2015
Raspberry using Python Session 1
Top 10 python ide
Python programming | Fundamentals of Python programming
Py Con 2009 Pumping Iron Into Python
Getting started with Linux and Python by Caffe
First python project
Python Scripting Tutorial for Beginners | Python Tutorial | Python Training |...
Introduction to python
Python Introduction
Raspberry using Python Session 3
gRPC 프레임워크를 만들며 알아보는 파이썬 - 파이콘2020
Mp24: Python in gaming industry
平行化你的工作 part1
Porting To Symbian
Machine Learning on Your Hand - Introduction to Tensorflow Lite Preview
Number of Computer Languages = 3
PyPy London Demo Evening 2013
Python 3.5: An agile, general-purpose development language.
Top python interview question and answer
Ad

Similar to Pythonic doesn't mean slow! (20)

PDF
Cluj.py Meetup: Extending Python in C
PDF
Magically run your code faster with PyPy
PPTX
Pypy is-it-ready-for-production-the-sequel
PDF
Understanding PyPy - PyConEs 14
PDF
PyCon2022 - Building Python Extensions
PPT
Euro python2011 High Performance Python
PDF
PyCon TW 2017 - PyPy's approach to construct domain-specific language runtime...
PDF
Using PyPy instead of Python for speed
PDF
PyPy 1.2: snakes never crawled so fast
PDF
The state of PyPy
PDF
Cython compiler
PDF
High Performance Python on Apache Spark
PDF
High-Performance Python On Spark
PDF
Building SciPy kernels with Pythran
PDF
Python. Why to learn?
PDF
Python, the Language of Science and Engineering for Engineers
PPTX
Hello World! with Python
PDF
Travis Oliphant "Python for Speed, Scale, and Science"
PDF
Python高级编程(二)
PPTX
Role of python in hpc
Cluj.py Meetup: Extending Python in C
Magically run your code faster with PyPy
Pypy is-it-ready-for-production-the-sequel
Understanding PyPy - PyConEs 14
PyCon2022 - Building Python Extensions
Euro python2011 High Performance Python
PyCon TW 2017 - PyPy's approach to construct domain-specific language runtime...
Using PyPy instead of Python for speed
PyPy 1.2: snakes never crawled so fast
The state of PyPy
Cython compiler
High Performance Python on Apache Spark
High-Performance Python On Spark
Building SciPy kernels with Pythran
Python. Why to learn?
Python, the Language of Science and Engineering for Engineers
Hello World! with Python
Travis Oliphant "Python for Speed, Scale, and Science"
Python高级编程(二)
Role of python in hpc
Ad

Recently uploaded (20)

PDF
Digital Strategies for Manufacturing Companies
PPTX
Operating system designcfffgfgggggggvggggggggg
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PPTX
Reimagine Home Health with the Power of Agentic AI​
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
Understanding Forklifts - TECH EHS Solution
PDF
How Creative Agencies Leverage Project Management Software.pdf
PDF
System and Network Administration Chapter 2
PPTX
CHAPTER 2 - PM Management and IT Context
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
top salesforce developer skills in 2025.pdf
PPTX
Introduction to Artificial Intelligence
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PPTX
ai tools demonstartion for schools and inter college
Digital Strategies for Manufacturing Companies
Operating system designcfffgfgggggggvggggggggg
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
Upgrade and Innovation Strategies for SAP ERP Customers
Reimagine Home Health with the Power of Agentic AI​
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
Understanding Forklifts - TECH EHS Solution
How Creative Agencies Leverage Project Management Software.pdf
System and Network Administration Chapter 2
CHAPTER 2 - PM Management and IT Context
How to Migrate SBCGlobal Email to Yahoo Easily
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
Design an Analysis of Algorithms II-SECS-1021-03
top salesforce developer skills in 2025.pdf
Introduction to Artificial Intelligence
Wondershare Filmora 15 Crack With Activation Key [2025
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
Odoo Companies in India – Driving Business Transformation.pdf
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
ai tools demonstartion for schools and inter college

Pythonic doesn't mean slow!

  • 1. Pythonic doesn't mean slow! Ronan Lamy
  • 2. About meAbout me PyPy core dev Python consultant and freelance developer Contact: Ronan.Lamy@gmail.com @ronanlamy
  • 3. We love PythonWe love Python
  • 4. Why Python?Why Python? Easy to learn Easy to read Simplicity Community Many libraries
  • 5. Technical reasonsTechnical reasons "Readability counts" Uniform object model Simple & expressive APIs Powerful abstractions Modularity/extensibility
  • 6. What about performance?What about performance? Who cares about performance?Who cares about performance?
  • 7. Workaround #1: Using high-performance librariesWorkaround #1: Using high-performance libraries
  • 8. GoodGood Feels like Python Also includes domain knowledge Actually the default option BadBad Somewhat slow Limited customisation options Can only use what's implemented
  • 9. Workaround #2: Rewrite in CWorkaround #2: Rewrite in C Cython C + cf Write a C extension 😱 Numba ...
  • 10. GoodGood Fast Developer has full control BadBad Different, less convenient, language Unoptimised parts can become signi cant again Python/C boundary is a bottleneck
  • 11. C implementations cause bad APIsC implementations cause bad APIs In [ ]: import numpy class myarray(numpy.ndarray): pass In [ ]: import pandas help(pandas.read_csv)
  • 12. Fast vs PythonicFast vs Pythonic
  • 13. PyPyPyPy Fast and compliant implementation of Python PyPy v7.2 released on 14 October Supports 2.7 and 3.6 JIT compiler GC tuned for Python
  • 14. PyPy - DemoPyPy - Demo In [2]: %%time class Quantity: def __init__(self, value, unit): self.value = value self.unit = unit def __add__(self, other): if isinstance(other, Quantity): if other.unit != self.unit: raise ValueError("units must match") else: return Quantity(self.value + other.value, self.unit) else: return NotImplemented def __str__(self): return f"{self.value} {self.unit}" def compute(n): total = Quantity(0, 'm') increment = Quantity(1., 'm') for i in range(n): total += increment return total N = 1_000_000_000 print(compute(N)) 3.6.9 (default, Jul 3 2019, 15:36:16) [GCC 5.4.0 20160609] 1000000000.0 m CPU times: user 29min 4s, sys: 112 ms, total: 29min 4s Wall time: 29min 4s
  • 15. How fast is PyPy?How fast is PyPy? It dependsIt depends Up to 1000x faster than CPython in extreme cases Up to 50x in more realistic cases 2-5x on "typical" applications Can be slower (short scripts, tests, ...)
  • 16. C extension supportC extension support cpyext = "Python.h for PyPy" numpy, scipy, pandas, scikit-learn, lxml, ... Cython + most extensions written in Cython 'pip install' works Wheels available at https://github.com/antocuni/pypy-wheels
  • 17. PyPy qualitiesPyPy qualities Make Pythonic code fast Abstractions for free Make Python a 1st-class language for HPC
  • 18. PyPy issuesPyPy issues Lags behind CPython Implementation details are different Need to understand GC and JIT to get best performance No conda Small community
  • 19. cpyext issuescpyext issues CPython API is huge Grey areas Patchy library support High overhead
  • 20. HPyHPy New C API No refcounting Replace PyObject* with opaque handles Don't expose implementation details https://github.com/pyhandle/hpy (https://github.com/pyhandle/hpy)
  • 21. HPy: plansHPy: plans In one yearIn one year CPython: implemented on top of existing API PyPy: much more ef cient than cpyext Used by Cython Long-termLong-term Replaces current C-API Used by all relevant implementations CPython free to experiment and modify internals
  • 22. SummarySummary PyPy makes pure-Python fast Compatible with PyData ecosystem Computing in Python becomes viable Complements traditional approaches to performance
  • 23. ContactContact IRC: #pypy on Freenode IRC pypy-dev @ python.org Questions? http://pypy.org (http://pypy.org)