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
Python Memory Management
Search
Tomek Paczkowski
November 28, 2013
Programming
0
59
Python Memory Management
A simple talk about simple problems with Python memory allocator
Tomek Paczkowski
November 28, 2013
Tweet
Share
More Decks by Tomek Paczkowski
See All by Tomek Paczkowski
Dispelling py.test magic
oinopion
0
770
Python Fest lightning talk
oinopion
0
88
Contributing to Django
oinopion
2
530
Django and Time Zones: New in the Trunk
oinopion
4
210
Other Decks in Programming
See All in Programming
Swift Testingのモチベを上げたい
stoticdev
2
220
機能が複雑化しても 頼りになる FactoryBotの話
tamikof
1
260
Boost Your Web Performance with Hyperdrive
chimame
1
150
Better Code Design in PHP
afilina
0
190
PRレビューのお供にDanger
stoticdev
1
250
15分で学ぶDuckDBの可愛い使い方 DuckDBの最近の更新
notrogue
3
870
ABEMA iOS 大規模プロジェクトにおける段階的な技術刷新 / ABEMA iOS Technology Upgrade
akkyie
1
260
Rubyと自由とAIと
yotii23
6
1.9k
Goで作るChrome Extensions / Fukuoka.go #21
n3xem
0
150
Drawing Heighway’s Dragon- Recursive Function Rewrite- From Imperative Style in Pascal 64 To Functional Style in Scala 3
philipschwarz
PRO
0
180
Devin入門 〜月500ドルから始まるAIチームメイトとの開発生活〜 / Introduction Devin 〜Development With AI Teammates〜
rkaga
3
1.4k
推しメソッドsource_locationのしくみを探る - はじめてRubyのコードを読んでみた
nobu09
2
370
Featured
See All Featured
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
40
2k
GitHub's CSS Performance
jonrohan
1030
460k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
280
13k
Designing for humans not robots
tammielis
250
25k
Measuring & Analyzing Core Web Vitals
bluesmoon
6
270
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.2k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
11
1.3k
Designing for Performance
lara
605
68k
Done Done
chrislema
182
16k
Building a Modern Day E-commerce SEO Strategy
aleyda
38
7.1k
Statistics for Hackers
jakevdp
797
220k
A better future with KSS
kneath
238
17k
Transcript
Python Memory Management Tomasz Paczkowski Pykonik, 28.11.2013
Case Study • Long lived web process • Periodically allocates
boatloads of memory • Never releases it
Distilled code def main():! big = alloc(100000)! small = alloc(1)!
del big! # memory not released
[Demo time]
Diagnose: Memory Fragmentation big small small big
Solution • Make better use of memory • Subprocess •
jemalloc* via LD_PRELOAD
Fun with Python allocator • Python does not use malloc
directly — too costly for small objects • Instead implements more sophisticated allocator on top of malloc
Pools for integers ints = range(5*1000*1000)! del ints! import gc;
gc.collect(2)
Free lists • For handful of most common types Python
keeps unused objects in so called free lists • Those are most significantly: lists, dictionaries, frames • Speeds up code execution immensely
[Demo time]
Conclusions • Sometimes memory leak is not what it seems
• glibc malloc is not the best of breed • do memory intensive work in subprocess • be mindful when using C extensions
Thanks. Questions?