$30 off During Our Annual Pro Sale. View Details »
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Fast Python, Slow Python by Alex Gaynor
Search
PyCon 2014
April 12, 2014
Programming
5
2.6k
Fast Python, Slow Python by Alex Gaynor
PyCon 2014
April 12, 2014
Tweet
Share
More Decks by PyCon 2014
See All by PyCon 2014
Postgres Performance for Humans by Craig Kerstiens
pycon2014
29
3.7k
Technical Onboarding, Training, and Mentoring by Kate Heddleston and Nicole Zuckerman
pycon2014
1
2.4k
"My big gay adventure. Making, releasing and selling an indie game made in python." by Luke Miller
pycon2014
2
1.6k
Farewell and Welcome Home, Python in Two Genders by Naomi_Ceder
pycon2014
1
760
Deliver Your Software in an Envelope by Augie Fackler and Nathaniel Manista
pycon2014
1
580
Hitchhikers Guide to Free and Open Source Participation by Elena Williams
pycon2014
6
1.2k
Localization Revisted (aka. Translations Evolved) by Ruchi Varshney
pycon2014
0
720
Smart Dumpster by Bradley E. Angell
pycon2014
0
550
Software Engineering for Hackers: Bridging the Two Solitudes by Tavish Armstrong
pycon2014
0
760
Other Decks in Programming
See All in Programming
UIデザインに役立つ 2025年の最新CSS / The Latest CSS for UI Design 2025
clockmaker
18
7.4k
AIコーディングエージェント(NotebookLM)
kondai24
0
190
ViewファーストなRailsアプリ開発のたのしさ
sugiwe
0
460
30分でDoctrineの仕組みと使い方を完全にマスターする / phpconkagawa 2025 Doctrine
ttskch
4
860
Why Kotlin? 電子カルテを Kotlin で開発する理由 / Why Kotlin? at Henry
agatan
2
7.2k
251126 TestState APIってなんだっけ?Step Functionsテストどう変わる?
east_takumi
0
320
新卒エンジニアのプルリクエスト with AI駆動
fukunaga2025
0
220
Go コードベースの構成と AI コンテキスト定義
andpad
0
120
Findy AI+の開発、運用におけるMCP活用事例
starfish719
0
260
実は歴史的なアップデートだと思う AWS Interconnect - multicloud
maroon1st
0
110
Cell-Based Architecture
larchanjo
0
120
AIコードレビューがチームの"文脈"を 読めるようになるまで
marutaku
0
350
Featured
See All Featured
Measuring & Analyzing Core Web Vitals
bluesmoon
9
710
[RailsConf 2023] Rails as a piece of cake
palkan
58
6.2k
Rebuilding a faster, lazier Slack
samanthasiow
84
9.3k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
130k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
17k
Leading Effective Engineering Teams in the AI Era
addyosmani
8
1.3k
Code Review Best Practice
trishagee
74
19k
Balancing Empowerment & Direction
lara
5
800
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
7.9k
Building an army of robots
kneath
306
46k
Imperfection Machines: The Place of Print at Facebook
scottboms
269
13k
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
Transcript
Fast Python, Slow Python Alex Gaynor
About me • Core developer of Django, PyPy, CPython, etc.
• Director of the Python Software Foundation • Work at Rackspace (Thanks!)
A talk about two things
What is performance?
Why do we care about performance?
Lies, damned lies, and benchmarks
Performance is specialization.
Systems performance
What is Python?
What Python Isn’t • Cython • C • Numba •
RPython
Excuses time
Dynamic typing
You can monkey patch anything
Slow vs Harder to optimize
PyPy
$ python! >>> print 2! 2! $ pypy! >>>> print
2! 2!
Let’s make a deal
How can we specialize our code?
Let’s talk about C
struct Point {! double x;! double y;! double z;! };!
class Point(objet):! def __init__(self, x, y, z):! self.x = x!
self.y = y! self.z = z!
point = {! "x": x,! "y": y,! "z": z,! }!
Dictionaries vs. Objects
std::unordered_map<std::string, double> point;! point["x"] = x;! point["y"] = y;! point["z"]
= z;!
Why don’t we care?
if [hex, bytes, bytes_le, fields, int].count(None) != 4:! raise TypeError('need
exactly one argument')!
if [hex, bytes, bytes_le, fields, int].count(None) != 4:! raise TypeError('need
exactly one argument')!
if (! (hex is None) + (bytes is None) +
(bytes_le is None) +! (fields is None) + (int is None)! ) != 4:! raise TypeError!
Python makes everything easier
Let’s talk about strings
char *data = malloc(1025);! while (true) {! size_t n =
read(fd, data, 1024);! data[n] = '\0';! char *start = data;! while (start < data + n) {! if (isspace(*start)) {! break;! }! start++;! }! printf("%s\n", start);! }!
while True:! data = os.read(fd, 1024)! print data.lstrip()!
Zero Buffer
from zero_buffer import Buffer! ! b = Buffer.allocate(8192)! with open(path,
"rb") as f:! b.read_from(f.fileno())! for part in b.view().split(b":"):! part.write_to(sys.stdout.fileno())! sys.stdout.write('\n')!
https://zero-buffer.readthedocs.org/ https://warehouse.python.org/project/zero_buffer/
A few more myths • Functions calls are really expensive
• Using only builtin data types will make your code fast • Don’t write Python in the style of Java or C
One Python
I hate heuristics
Let’s take a lesson…
Thank you! Questions? https://speakerdeck.com/alex/