~/talk

Memory management in CPython, fast or slow?

Talkat PyCon US 2026 · 2026-05-13..05-19· [python]
links:none on file
slides:none on file

CPython spends one third of runtime on memory management and currently services roughly half of allocations from small-object free lists; there are 32 size classes up to 512 bytes, 41 per-class free lists (20 for tuples), arenas are ~2 MB and pages typically 4 KB. Fragmentation and thread‑state lookups cost time; stack-local ref elision removes about 90% of local ref ops and converting free lists to size-class allocation plus JIT unboxing aims to push common-case allocation to 99% from free lists and cut overhead.

AI-written summary · about

  1. 0:00Memory management in CPython
  2. 2:13Reference counting in CPython
  3. 3:36Free lists for fast allocation
  4. 5:45Pages and arenas in CPython
  5. 7:28Size classes and fragmentation
  6. 11:00Inefficiencies in CPython memory
  7. 13:08Thread state overhead
  8. 15:55Allocator overheads
  9. 17:21Free list limitations
  10. 18:22Optimizing reference counting
  11. 19:24Future free list improvements
  12. 20:47Fast and slow allocation paths
  13. 21:49JIT optimizations for tuples
  14. 22:51Conclusion and contributions
  15. 23:13Cyclic garbage collection
  16. 27:10Q&A on free lists
~/search
type to search 6,249 conferences, 138,987 speakers and 185,172 talks
~/help
cmdctrl k
search every conference, speaker and series
/
focus the filter search
h
home
c
conferences
s
speakers
e
series
t
light / dark — the status bar button does the same
?
this help
esc
close this, then clear every filter — or just the search, while you are typing in it

Ignored while you are typing. Pages without a filter rail have no search to focus.