Tags
object-layout
4 posts
A NamedTuple Read Cost 0.81x a Plain One, Then 1.9x
On CPython 3.10 a NamedTuple attribute read cost 0.81x a read through an instance dictionary. On 3.11 it costs 1.90x. Nothing about NamedTuple changed.
getsizeof Reports 296 Bytes, Then 96, for the Same Class
sys.getsizeof reports 296 bytes for a class's first instance dict and 96 once twenty-six exist. The instance itself costs 96 bytes and getsizeof says 48.
Slots Did Not Get Slower, One Build Did
A read through __slots__ costs 24% more than one through an instance dictionary on CPython 3.13.2. Rebuild the same version and the gap goes away.
The Shape of a Python Object
An instance with three attributes costs 96 bytes, not the 344 sys.getsizeof reports, and __slots__ read 12% slower on the CPython 3.13.2 build measured here.