Memoirs of a Python Object: Memory Management and Improving Performance
summary
Shows that CPython objects are C structs (the PyObject struct) with a reference count and type info, and that reference counting plus a generational tracing GC causes full-process pauses — graphs show collections over 2 seconds. Practical fixes: use slots to shrink instance size (example: ~60% reduction), move hot code into C via Cython (example: 15x CPU and memory speedup), and preserve copy‑on‑write by using gc.freeze before forking (Instagram raised capacity ~10% after applying this).
AI-written summary · about
chapters (9)
- 0:00Introduction to Python memory
- 2:19Python objects and memory
- 5:22Reference counting
- 8:25Garbage collection algorithms
- 11:31Generational garbage collection
- 13:24Memory optimization techniques
- 15:32C extensions for performance
- 16:43Instagram case study: GC Freeze
- 21:53Conclusion
related talks
28mMemory management in CPython, fast or slow?
25mIs it me or Python memory management? 🤔💻
01h 18mPython 103: Mmmm... Understanding Python's Memory Model, Mutability, and Methods
26mPython Performance at Scale - Making Python Faster at Instagram
27mDemystifying Python’s Generational Garbage Collector
31mIntroducing Immortal Objects: Building Block Towards a Multi-core Python Runtime
59mMyths and fairy tales around Python performance
01h 18mPython 103: Mmmm... Understanding Python's Memory Model, Mutability, and Methods
