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
68
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
860
Python Fest lightning talk
oinopion
0
90
Contributing to Django
oinopion
2
560
Django and Time Zones: New in the Trunk
oinopion
4
210
Other Decks in Programming
See All in Programming
オンデバイスAIとXcode
ryodeveloper
0
360
EMこそClaude Codeでコード調査しよう
shibayu36
0
520
20251016_Rails News ~Rails 8.1の足音を聴く~
morimorihoge
3
900
SidekiqでAIに商品説明を生成させてみた
akinko_0915
0
110
AIと人間の共創開発!OSSで試行錯誤した開発スタイル
mae616
2
850
組込みだけじゃない!TinyGo で始める無料クラウド開発入門
otakakot
2
380
AI時代に必須!状況言語化スキル / ai-context-verbalization
minodriven
2
260
Module Proxyのマニアックな話 / Niche Topics in Module Proxy
kuro_kurorrr
0
360
Migration to Signals, Resource API, and NgRx Signal Store
manfredsteyer
PRO
0
140
Amazon ECS Managed Instances が リリースされた!キャッチアップしよう!! / Let's catch up Amazon ECS Managed Instances
cocoeyes02
0
120
CSC509 Lecture 08
javiergs
PRO
0
270
AI 駆動開発におけるコミュニティと AWS CDK の価値
konokenj
5
310
Featured
See All Featured
VelocityConf: Rendering Performance Case Studies
addyosmani
333
24k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
36
6.1k
How STYLIGHT went responsive
nonsquared
100
5.9k
The Pragmatic Product Professional
lauravandoore
36
7k
Six Lessons from altMBA
skipperchong
29
4k
Principles of Awesome APIs and How to Build Them.
keavy
127
17k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
140
34k
Designing for Performance
lara
610
69k
What’s in a name? Adding method to the madness
productmarketing
PRO
24
3.7k
Automating Front-end Workflow
addyosmani
1371
200k
Navigating Team Friction
lara
190
15k
Testing 201, or: Great Expectations
jmmastey
46
7.7k
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?