Message396031
Andrei: The size of an instance of Semaphore is 48 bytes + 104 more bytes for the __dict__ containing its three attributes (ignoring the cost of the attributes themselves). A slotted class with three attributes only needs 56 bytes of overhead per-instance (it has no __dict__, so the 56 is the total cost). Dropping overhead of the instances by >60% can make a difference if you're really making many thousands of them.
Personally, I think Python level classes should generally default to using __slots__ unless the classes are explicitly not for subclassing; not using __slots__ means all subclasses have their hands tied by the decision of the parent class. Perhaps explicitly opting in to __weakref__ (which __slots__ removes by default) to allow weak referencing, but it's fairly rare a class *needs* to otherwise allow the creation of arbitrary attributes. |
|
Date |
User |
Action |
Args |
2021-06-18 03:57:38 | josh.r | set | recipients:
+ josh.r, asvetlov, serhiy.storchaka, yselivanov, andrei.avk, bluenix |
2021-06-18 03:57:38 | josh.r | set | messageid: <1623988658.33.0.65934140046.issue44318@roundup.psfhosted.org> |
2021-06-18 03:57:38 | josh.r | link | issue44318 messages |
2021-06-18 03:57:38 | josh.r | create | |
|