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
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
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.7k
Farewell and Welcome Home, Python in Two Genders by Naomi_Ceder
pycon2014
1
770
Deliver Your Software in an Envelope by Augie Fackler and Nathaniel Manista
pycon2014
1
600
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
560
Software Engineering for Hackers: Bridging the Two Solitudes by Tavish Armstrong
pycon2014
0
770
Other Decks in Programming
See All in Programming
「ブロックテーマでは再現できない」は本当か?
inc2734
0
710
FOSDEM 2026: STUNMESH-go: Building P2P WireGuard Mesh Without Self-Hosted Infrastructure
tjjh89017
0
150
AI Agent Tool のためのバックエンドアーキテクチャを考える #encraft
izumin5210
6
1.8k
Spinner 軸ズレ現象を調べたらレンダリング深淵に飲まれた #レバテックMeetup
bengo4com
1
230
AI時代の認知負荷との向き合い方
optfit
0
150
なぜSQLはAIぽく見えるのか/why does SQL look AI like
florets1
0
450
humanlayerのブログから学ぶ、良いCLAUDE.mdの書き方
tsukamoto1783
0
180
AI時代のキャリアプラン「技術の引力」からの脱出と「問い」へのいざない / tech-gravity
minodriven
20
6.9k
React 19でつくる「気持ちいいUI」- 楽観的UIのすすめ
himorishige
11
6k
【卒業研究】会話ログ分析によるユーザーごとの関心に応じた話題提案手法
momok47
0
190
HTTPプロトコル正しく理解していますか? 〜かわいい猫と共に学ぼう。ฅ^•ω•^ฅ ニャ〜
hekuchan
2
680
CSC307 Lecture 07
javiergs
PRO
0
550
Featured
See All Featured
Why You Should Never Use an ORM
jnunemaker
PRO
61
9.7k
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
160
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.3k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
16
1.8k
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
110
Navigating Team Friction
lara
192
16k
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
57
50k
What Being in a Rock Band Can Teach Us About Real World SEO
427marketing
0
170
The Power of CSS Pseudo Elements
geoffreycrofte
80
6.1k
Documentation Writing (for coders)
carmenintech
77
5.2k
Winning Ecommerce Organic Search in an AI Era - #searchnstuff2025
aleyda
0
1.9k
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
62
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/