The main problem of dicts is that they're really heavy memory-wise, even with key-shared dicts and stuff.
Your dict is 232 bytes, the equivalent tuple is 56.
Your dict is 232 bytes, the equivalent tuple is 56.
Although there seems to be some kind of trickery happening there, because if I make the class accept 3 floats instead of two, neither the class nor the instance get larger.
> Although there seems to be some kind of trickery happening there, because if I make the class accept 3 floats instead of two, neither the class nor the instance get larger.
The dataclass stores stuff in a normal instance __dict__ and sys.getsize is not recursive.
namedtuples are variable-size instances, they store the attributes “inline”.