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

What's hot (20)

PDF
UNSW Australia Robocup Recap Hefei 2015
Peter Schmidt
 
PDF
Raspberry using Python Session 1
Mohamed Abd Ela'al
 
PPTX
Top 10 python ide
Saravanakumar viswanathan
 
PPTX
Python programming | Fundamentals of Python programming
KrishnaMildain
 
PPT
Py Con 2009 Pumping Iron Into Python
Sarah Dutkiewicz
 
PDF
Getting started with Linux and Python by Caffe
Lihang Li
 
PPTX
First python project
Neetu Jain
 
PDF
Python Scripting Tutorial for Beginners | Python Tutorial | Python Training |...
Edureka!
 
PDF
Introduction to python
Agung Wahyudi
 
PPT
Python Introduction
Mohammad Javad Beheshtian
 
PDF
Raspberry using Python Session 3
Mohamed Abd Ela'al
 
PDF
gRPC 프레임워크를 만들며 알아보는 파이썬 - 파이콘2020
재현 신
 
PDF
Mp24: Python in gaming industry
Montreal Python
 
PDF
平行化你的工作 part1
Shuen-Huei Guan
 
PPT
Porting To Symbian
Mark Wilcox
 
PPTX
Machine Learning on Your Hand - Introduction to Tensorflow Lite Preview
Modulabs
 
PDF
Number of Computer Languages = 3
Ram Sekhar
 
PDF
PyPy London Demo Evening 2013
Carl Friedrich Bolz
 
PDF
Python 3.5: An agile, general-purpose development language.
Carlos Miguel Ferreira
 
PPTX
Top python interview question and answer
Ankita Singh
 
UNSW Australia Robocup Recap Hefei 2015
Peter Schmidt
 
Raspberry using Python Session 1
Mohamed Abd Ela'al
 
Top 10 python ide
Saravanakumar viswanathan
 
Python programming | Fundamentals of Python programming
KrishnaMildain
 
Py Con 2009 Pumping Iron Into Python
Sarah Dutkiewicz
 
Getting started with Linux and Python by Caffe
Lihang Li
 
First python project
Neetu Jain
 
Python Scripting Tutorial for Beginners | Python Tutorial | Python Training |...
Edureka!
 
Introduction to python
Agung Wahyudi
 
Python Introduction
Mohammad Javad Beheshtian
 
Raspberry using Python Session 3
Mohamed Abd Ela'al
 
gRPC 프레임워크를 만들며 알아보는 파이썬 - 파이콘2020
재현 신
 
Mp24: Python in gaming industry
Montreal Python
 
平行化你的工作 part1
Shuen-Huei Guan
 
Porting To Symbian
Mark Wilcox
 
Machine Learning on Your Hand - Introduction to Tensorflow Lite Preview
Modulabs
 
Number of Computer Languages = 3
Ram Sekhar
 
PyPy London Demo Evening 2013
Carl Friedrich Bolz
 
Python 3.5: An agile, general-purpose development language.
Carlos Miguel Ferreira
 
Top python interview question and answer
Ankita Singh
 

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

PDF
Cluj.py Meetup: Extending Python in C
Steffen Wenz
 
PDF
Magically run your code faster with PyPy
Ronan Lamy
 
PPTX
Pypy is-it-ready-for-production-the-sequel
Mark Rees
 
PDF
Understanding PyPy - PyConEs 14
fcofdezc
 
PDF
PyCon2022 - Building Python Extensions
Henry Schreiner
 
PPT
Euro python2011 High Performance Python
Ian Ozsvald
 
PDF
PyCon TW 2017 - PyPy's approach to construct domain-specific language runtime...
Tsundere Chen
 
PDF
Using PyPy instead of Python for speed
Enplore AB
 
PDF
PyPy 1.2: snakes never crawled so fast
PyCon Italia
 
PDF
The state of PyPy
m_r_e
 
PDF
Cython compiler
Tanikella Sai Abhijyan
 
PDF
High Performance Python on Apache Spark
Wes McKinney
 
PDF
High-Performance Python On Spark
Jen Aman
 
PDF
Building SciPy kernels with Pythran
Ralf Gommers
 
PDF
Python. Why to learn?
Oleh Korkh
 
PDF
Python, the Language of Science and Engineering for Engineers
Boey Pak Cheong
 
PPTX
Hello World! with Python
Dhanashree Prasad
 
PDF
Travis Oliphant "Python for Speed, Scale, and Science"
Fwdays
 
PDF
Python高级编程(二)
Qiangning Hong
 
PPTX
Role of python in hpc
Dr Reeja S R
 
Cluj.py Meetup: Extending Python in C
Steffen Wenz
 
Magically run your code faster with PyPy
Ronan Lamy
 
Pypy is-it-ready-for-production-the-sequel
Mark Rees
 
Understanding PyPy - PyConEs 14
fcofdezc
 
PyCon2022 - Building Python Extensions
Henry Schreiner
 
Euro python2011 High Performance Python
Ian Ozsvald
 
PyCon TW 2017 - PyPy's approach to construct domain-specific language runtime...
Tsundere Chen
 
Using PyPy instead of Python for speed
Enplore AB
 
PyPy 1.2: snakes never crawled so fast
PyCon Italia
 
The state of PyPy
m_r_e
 
Cython compiler
Tanikella Sai Abhijyan
 
High Performance Python on Apache Spark
Wes McKinney
 
High-Performance Python On Spark
Jen Aman
 
Building SciPy kernels with Pythran
Ralf Gommers
 
Python. Why to learn?
Oleh Korkh
 
Python, the Language of Science and Engineering for Engineers
Boey Pak Cheong
 
Hello World! with Python
Dhanashree Prasad
 
Travis Oliphant "Python for Speed, Scale, and Science"
Fwdays
 
Python高级编程(二)
Qiangning Hong
 
Role of python in hpc
Dr Reeja S R
 
Ad

Recently uploaded (20)

PDF
The 5 Reasons for IT Maintenance - Arna Softech
Arna Softech
 
PDF
Simplify React app login with asgardeo-sdk
vaibhav289687
 
PDF
Empower Your Tech Vision- Why Businesses Prefer to Hire Remote Developers fro...
logixshapers59
 
PDF
ERP Consulting Services and Solutions by Contetra Pvt Ltd
jayjani123
 
PDF
How to Hire AI Developers_ Step-by-Step Guide in 2025.pdf
DianApps Technologies
 
PPTX
Foundations of Marketo Engage - Powering Campaigns with Marketo Personalization
bbedford2
 
PPTX
Home Care Tools: Benefits, features and more
Third Rock Techkno
 
PDF
TheFutureIsDynamic-BoxLang witch Luis Majano.pdf
Ortus Solutions, Corp
 
PPTX
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PDF
Technical-Careers-Roadmap-in-Software-Market.pdf
Hussein Ali
 
PPTX
Milwaukee Marketo User Group - Summer Road Trip: Mapping and Personalizing Yo...
bbedford2
 
PPTX
OpenChain @ OSS NA - In From the Cold: Open Source as Part of Mainstream Soft...
Shane Coughlan
 
PPTX
Comprehensive Risk Assessment Module for Smarter Risk Management
EHA Soft Solutions
 
PDF
Wondershare PDFelement Pro Crack for MacOS New Version Latest 2025
bashirkhan333g
 
PDF
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
PDF
4K Video Downloader Plus Pro Crack for MacOS New Download 2025
bashirkhan333g
 
PDF
MiniTool Partition Wizard Free Crack + Full Free Download 2025
bashirkhan333g
 
PDF
AI + DevOps = Smart Automation with devseccops.ai.pdf
Devseccops.ai
 
PDF
IDM Crack with Internet Download Manager 6.42 Build 43 with Patch Latest 2025
bashirkhan333g
 
PPTX
Agentic Automation Journey Series Day 2 – Prompt Engineering for UiPath Agents
klpathrudu
 
The 5 Reasons for IT Maintenance - Arna Softech
Arna Softech
 
Simplify React app login with asgardeo-sdk
vaibhav289687
 
Empower Your Tech Vision- Why Businesses Prefer to Hire Remote Developers fro...
logixshapers59
 
ERP Consulting Services and Solutions by Contetra Pvt Ltd
jayjani123
 
How to Hire AI Developers_ Step-by-Step Guide in 2025.pdf
DianApps Technologies
 
Foundations of Marketo Engage - Powering Campaigns with Marketo Personalization
bbedford2
 
Home Care Tools: Benefits, features and more
Third Rock Techkno
 
TheFutureIsDynamic-BoxLang witch Luis Majano.pdf
Ortus Solutions, Corp
 
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Technical-Careers-Roadmap-in-Software-Market.pdf
Hussein Ali
 
Milwaukee Marketo User Group - Summer Road Trip: Mapping and Personalizing Yo...
bbedford2
 
OpenChain @ OSS NA - In From the Cold: Open Source as Part of Mainstream Soft...
Shane Coughlan
 
Comprehensive Risk Assessment Module for Smarter Risk Management
EHA Soft Solutions
 
Wondershare PDFelement Pro Crack for MacOS New Version Latest 2025
bashirkhan333g
 
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
4K Video Downloader Plus Pro Crack for MacOS New Download 2025
bashirkhan333g
 
MiniTool Partition Wizard Free Crack + Full Free Download 2025
bashirkhan333g
 
AI + DevOps = Smart Automation with devseccops.ai.pdf
Devseccops.ai
 
IDM Crack with Internet Download Manager 6.42 Build 43 with Patch Latest 2025
bashirkhan333g
 
Agentic Automation Journey Series Day 2 – Prompt Engineering for UiPath Agents
klpathrudu
 
Ad

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: [email protected] @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)