Signals and Threads

Memory Management with Stephen Dolan

38 snips
Jan 5, 2022
Ask episode
AI Snips
Chapters
Transcript
Episode notes
ANECDOTE

Reference Counting Excels For Large Single-Owner Buffers

  • Reference counting shines for single-reference, pointer-free large objects like big I/O buffers because counts go from 0→1→0 with no pointer traversal.
  • Tracing collectors can lag and cycle through many buffers before reclaiming them, causing higher peak memory usage.
INSIGHT

Generational Hypothesis Makes Minor Collections Cheap

  • The generational hypothesis holds across languages: most newly allocated objects die quickly, so a tiny nursery with fast bump allocation eliminates many heap allocations.
  • Minor collections scan the small region and promote only survivors, avoiding expensive major-heap allocation for temporaries.
ADVICE

Use Local Stack Allocation To Cut GC Pressure

  • Add safe local (stack) allocation for short-lived temporaries to avoid minor-heap churn and improve cache reuse.
  • Stack allocations cost a register subtraction and reuse the same cache lines, reducing promotions and GC pressure compared to minor allocations.
Get the Snipd Podcast app to discover more snips from this episode
Get the app