Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
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.3k
"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
740
Deliver Your Software in an Envelope by Augie Fackler and Nathaniel Manista
pycon2014
1
550
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
700
Smart Dumpster by Bradley E. Angell
pycon2014
0
530
Software Engineering for Hackers: Bridging the Two Solitudes by Tavish Armstrong
pycon2014
0
740
Other Decks in Programming
See All in Programming
テスト駆動Kaggle
isax1015
1
510
おやつのお供はお決まりですか?@WWDC25 Recap -Japan-\(region).swift
shingangan
0
140
AIエージェントはこう育てる - GitHub Copilot Agentとチームの共進化サイクル
koboriakira
0
620
20250704_教育事業におけるアジャイルなデータ基盤構築
hanon52_
5
910
20250628_非エンジニアがバイブコーディングしてみた
ponponmikankan
0
710
顧客の画像データをテラバイト単位で配信する 画像サーバを WebP にした際に起こった課題と その対応策 ~継続的な取り組みを添えて~
takutakahashi
1
310
Modern Angular with Signals and Signal Store:New Rules for Your Architecture @enterJS Advanced Angular Day 2025
manfredsteyer
PRO
0
240
The Modern View Layer Rails Deserves: A Vision For 2025 And Beyond @ RailsConf 2025, Philadelphia, PA
marcoroth
2
670
生成AI時代のコンポーネントライブラリの作り方
touyou
1
260
脱Riverpod?fqueryで考える、TanStack Queryライクなアーキテクチャの可能性
ostk0069
0
340
Deep Dive into ~/.claude/projects
hiragram
14
11k
The Niche of CDK Grant オブジェクトって何者?/the-niche-of-cdk-what-isgrant-object
hassaku63
1
500
Featured
See All Featured
A better future with KSS
kneath
238
17k
Being A Developer After 40
akosma
90
590k
Thoughts on Productivity
jonyablonski
69
4.7k
Facilitating Awesome Meetings
lara
54
6.5k
Adopting Sorbet at Scale
ufuk
77
9.5k
The Cult of Friendly URLs
andyhume
79
6.5k
GitHub's CSS Performance
jonrohan
1031
460k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
48
2.9k
Scaling GitHub
holman
460
140k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
107
19k
Keith and Marios Guide to Fast Websites
keithpitt
411
22k
Gamification - CAS2011
davidbonilla
81
5.4k
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/