This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author josh.r
Recipients andrei.avk, asvetlov, bluenix, josh.r, serhiy.storchaka, yselivanov
Date 2021-06-18.03:57:38
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1623988658.33.0.65934140046.issue44318@roundup.psfhosted.org>
In-reply-to
Content
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.
History
Date User Action Args
2021-06-18 03:57:38josh.rsetrecipients: + josh.r, asvetlov, serhiy.storchaka, yselivanov, andrei.avk, bluenix
2021-06-18 03:57:38josh.rsetmessageid: <1623988658.33.0.65934140046.issue44318@roundup.psfhosted.org>
2021-06-18 03:57:38josh.rlinkissue44318 messages
2021-06-18 03:57:38josh.rcreate