Tags
memory
3 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.
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.