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, methane
Date 2020-03-30.15:13:56
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1585581236.94.0.571794171265.issue40116@roundup.psfhosted.org>
In-reply-to
Content
The current implementation of dicts prevents keys from being shared when the order of attribute differs from the first instance created.
This can potentially use a considerably larger amount of memory than expected.

Consider the class:

class C:

   opt = DEFAULT

   def __init__(self, attr, optional=None):
       if optional:
           self.opt = optional
       self.attr = attr

This is a reasonable way to write a class, but has unpredictable memory use.
In the attached example, per-instance dict size goes from 104 bytes to 232 bytes when sharing is prevented.

The language specification says that the dicts maintain insertion order, but the wording implies that this only to explicit dictionaries, not instance attribute or other namespace dicts.

Either we should allow key sharing in these cases, or clarify the documentation.
History
Date User Action Args
2020-03-30 15:13:56Mark.Shannonsetrecipients: + Mark.Shannon, methane
2020-03-30 15:13:56Mark.Shannonsetmessageid: <1585581236.94.0.571794171265.issue40116@roundup.psfhosted.org>
2020-03-30 15:13:56Mark.Shannonlinkissue40116 messages
2020-03-30 15:13:56Mark.Shannoncreate