Loading Python for AI Engineering...
In CPython, every variable is a pointer to a heap-allocated C struct called PyObject. A basic integer requires 28 bytes rather than 4 or 8 bytes due to reference counts (ob_refcnt) and type descriptor pointers (ob_type).
“PyObject is like shipping every single jellybean in its own individual cardboard box with tracking barcodes and inspector stamps, rather than packing 10,000 jellybeans in one tight bag.”
Storing millions of numerical embeddings in native Python lists of floats, consuming 8x to 12x more RAM than a single float32 tensor buffer.
import sys
val = 42
print(f"Size of int 42: {sys.getsizeof(val)} bytes") # 28 bytes!
# An array of 1,000,000 Python ints consumes ~8MB for pointers + ~28MB for PyObjects = ~36MB
# A NumPy int32 array consumes exactly 4MB (1M * 4 bytes).