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.5k
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.6k
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
720
Deliver Your Software in an Envelope by Augie Fackler and Nathaniel Manista
pycon2014
1
540
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
690
Smart Dumpster by Bradley E. Angell
pycon2014
0
520
Software Engineering for Hackers: Bridging the Two Solitudes by Tavish Armstrong
pycon2014
0
720
Other Decks in Programming
See All in Programming
データの整合性を保つ非同期処理アーキテクチャパターン / Async Architecture Patterns
mokuo
55
19k
React 19アップデートのために必要なこと
uhyo
8
1.5k
XStateを用いた堅牢なReact Components設計~複雑なClient Stateをシンプルに~ @React Tokyo ミートアップ #2
kfurusho
1
990
データベースのオペレーターであるCloudNativePGがStatefulSetを使わない理由に迫る
nnaka2992
0
240
LINE messaging APIを使ってGoogleカレンダーと連携した予約ツールを作ってみた
takumakoike
0
120
The Clean ArchitectureがWebフロントエンドでしっくりこないのは何故か / Why The Clean Architecture does not fit with Web Frontend
twada
PRO
1
240
color-scheme: light dark; を完全に理解する
uhyo
7
500
.NET Frameworkでも汎用ホストが使いたい!
tomokusaba
0
200
CSS Linter による Baseline サポートの仕組み
ryo_manba
1
160
もう少しテストを書きたいんじゃ〜 #phpstudy
o0h
PRO
19
4.1k
責務と認知負荷を整える! 抽象レベルを意識した関心の分離
yahiru
8
1.5k
CDKを使ったPagerDuty連携インフラのテンプレート化
shibuya_shogo
0
110
Featured
See All Featured
Build The Right Thing And Hit Your Dates
maggiecrowley
34
2.5k
Reflections from 52 weeks, 52 projects
jeffersonlam
348
20k
Rails Girls Zürich Keynote
gr2m
94
13k
Fantastic passwords and where to find them - at NoRuKo
philnash
51
3k
RailsConf 2023
tenderlove
29
1k
jQuery: Nuts, Bolts and Bling
dougneiner
63
7.7k
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
100
18k
Building an army of robots
kneath
303
45k
Six Lessons from altMBA
skipperchong
27
3.6k
Optimising Largest Contentful Paint
csswizardry
34
3.1k
Speed Design
sergeychernyshev
27
810
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/