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 Mark.Shannon
Recipients Mark.Shannon
Date 2021-08-04.07:57:16
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1628063836.31.0.548816977554.issue44821@roundup.psfhosted.org>
In-reply-to
Content
Currently, instance dictionaries (__dict__ attribute) are created lazily when the first attribute is set.

This is bad for performance for a number of reasons:
1. It causes additional checks on every attribute access.
2. It causes allocation of the object and its dict to be temporarily separated, most likely leading to increased physical separation and worse cache behavior.
3. It has a large impact on specialization, as the first SET_ATTR for an object has to behave differently.


Creating a __dict__ lazily does not save a significant amount of memory.
If an object has a __dict__ slot, then it will end up with a dictionary before it dies in almost all cases.

Many objects, e.g. ints, floats, don't have a dictionary. They are unaffected.

Plain python objects that have no instance attributes are extremely rare, unless they have __slots__, in which case they don't have a dictionary anyway.

The remaining case is subclasses of builtin types that do not add extra attributes, but these are rare, and the overhead of an empty dictionary is only 64 bytes (on a 64 bit machine).
History
Date User Action Args
2021-08-04 07:57:16Mark.Shannonsetrecipients: + Mark.Shannon
2021-08-04 07:57:16Mark.Shannonsetmessageid: <1628063836.31.0.548816977554.issue44821@roundup.psfhosted.org>
2021-08-04 07:57:16Mark.Shannonlinkissue44821 messages
2021-08-04 07:57:16Mark.Shannoncreate