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
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
PyCon 2014
April 12, 2014
Programming
2.6k
5
Share
Fast Python, Slow Python by Alex Gaynor
PyCon 2014
April 12, 2014
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.7k
Farewell and Welcome Home, Python in Two Genders by Naomi_Ceder
pycon2014
1
790
Deliver Your Software in an Envelope by Augie Fackler and Nathaniel Manista
pycon2014
1
620
Hitchhikers Guide to Free and Open Source Participation by Elena Williams
pycon2014
6
1.3k
Localization Revisted (aka. Translations Evolved) by Ruchi Varshney
pycon2014
0
730
Smart Dumpster by Bradley E. Angell
pycon2014
0
570
Software Engineering for Hackers: Bridging the Two Solitudes by Tavish Armstrong
pycon2014
0
780
Other Decks in Programming
See All in Programming
実践ハーネスエンジニアリング:ステアリングループを実例から読み解く / Practical Harness Engineering: Understanding Steering Loops Through Real-World Examples
nrslib
5
5.5k
UaaL×Androidアプリのメモリ計測 — Memory Profilerの先へ
rio432
0
160
決定論 vs 確率論:Gemini 3 FlashとTF-IDFを組み合わせた「法規判定エンジン」の構築
shukob
0
160
AI時代になぜ書くのか
mutsumix
0
410
AI Agent と正しく分析するための環境作り
yoshyum
2
500
サーバーレスで作る、動画データ管理基盤
oyasumipants
0
190
Symfony AI in Action - SymfonyLive Berlin 2026
chr_hertel
1
150
書籍「ユーザーストーリーマッピング」が私のバイブル
asumikam
4
490
HTML-Aware ERB: The Path to Reactive Rendering @ RubyKaigi 2026, Hakodate, Japan
marcoroth
0
710
Road to RubyKaigi: Play Hard(ware)
makicamel
1
580
t *testing.T は どこからやってくるの?
otakakot
1
940
Claude CodeでETLジョブ実行テストを自動化してみた
yoshikikasama
0
1.2k
Featured
See All Featured
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
2
300
The Mindset for Success: Future Career Progression
greggifford
PRO
0
330
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
122
21k
How Software Deployment tools have changed in the past 20 years
geshan
0
33k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
32
3k
New Earth Scene 8
popppiees
3
2.2k
SEO Brein meetup: CTRL+C is not how to scale international SEO
lindahogenes
1
2.6k
AI: The stuff that nobody shows you
jnunemaker
PRO
7
640
The Power of CSS Pseudo Elements
geoffreycrofte
82
6.2k
jQuery: Nuts, Bolts and Bling
dougneiner
66
8.5k
What Being in a Rock Band Can Teach Us About Real World SEO
427marketing
0
230
Between Models and Reality
mayunak
4
290
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/