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
2.6k
5
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
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
28
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
810
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
740
Smart Dumpster by Bradley E. Angell
pycon2014
0
590
Software Engineering for Hackers: Bridging the Two Solitudes by Tavish Armstrong
pycon2014
0
790
Other Decks in Programming
See All in Programming
源内ハンズオン概要編
hideg
0
210
わからない話を追いかけたら、プログラミング言語を作る側にいた
ydah
3
550
AIと壁打ちしながら進めるコスト管理
fufuhu
2
1.7k
Loosening the Reins: Go Generics Get More Flexible
kuro_kurorrr
0
330
AIに既存システムを理解させる技術 ~レガシーを見捨てないハーネスエンジニアリング入門~
ochtum
0
150
ソフトウェアラスタライザ
fadis
1
670
FastAPI の並行処理モデルを完全に理解する
hoto17296
8
3k
進化を続けるGo toolsの現在地 / The Current State of Ever-Evolving Go Tools
hond0413
0
260
MySQLとPostgreSQLって何が違うの?
akagami
0
140
AWS Transform Customによる Spring Boot 2.xから4.xへのVerUp
satoshi256kbyte
2
110
Pythonの実行はどこまで賢くなったのか? CPythonとPyPyから見る最適化のしくみ
curekoshimizu
3
2k
Deep dive into the select statement (GopherCon UK)
jespino
0
110
Featured
See All Featured
Building Applications with DynamoDB
mza
96
7.2k
Marketing to machines
jonoalderson
1
5.7k
Ethics towards AI in product and experience design
skipperchong
2
350
Bash Introduction
62gerente
615
220k
DevOps and Value Stream Thinking: Enabling flow, efficiency and business value
helenjbeal
1
360
Why Our Code Smells
bkeepers
PRO
340
58k
The B2B funnel & how to create a winning content strategy
katarinadahlin
PRO
1
490
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
1
1.6k
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
500
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.8k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
8.3k
A designer walks into a library…
pauljervisheath
211
24k
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/