core.py

Episode 27: Calling Things, Part 1

18 snips
Dec 7, 2025
Dive into the intricacies of Python's calling conventions and internal structures. Discover how the call stack functions and why it's pivotal to recursion. The hosts dissect Python's frame structure and evaluate the pros and cons of stack versus register-based interpreters. Learn about optimizing frames in Python 3.11, and how exceptions unfold within this model. Plus, insights on a new profiling tool and improvements in the standard library make for an engaging discussion.
Ask episode
AI Snips
Chapters
Transcript
Episode notes
INSIGHT

Python Uses Heap Frames, Not C Stack

  • CPython implements its own call frames separate from the C stack, storing them on the heap as Python-managed structures.
  • Every Python function call creates a frame that holds code, globals, locals, and a link to the previous frame for traceback and control flow.
INSIGHT

What Lives Inside A Python Frame

  • A Python frame contains bookkeeping (globals, code object, prev frame), a fast locals array, and an evaluation stack for bytecode execution.
  • Locals and cell variables index by position for speed, making local access much faster than global lookups.
INSIGHT

Python's Stack-Based Bytecode Model

  • CPython uses a stack-machine bytecode where intermediate results are pushed to an evaluation stack during execution.
  • Stack machines make bytecode denser but incur more push/pop traffic compared to register machines.
Get the Snipd Podcast app to discover more snips from this episode
Get the app