Slots, slots, slots, everybody: an exploration of __slots__
summary
Explains that using __slots__ replaces per-instance dicts with a packed array plus descriptors, saving about 10 MB in a 100k-instance benchmark and making attribute access roughly 30% faster in a 1M-access timeit run. Demonstrates the experiments using tracemalloc for memory and timeit for speed, shows subclassing requires re-declaring slots, compares to namedtuple which is ~20% larger than slotted but ~2x slower for attribute access.
AI-written summary · about
