Message365319
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. |
|
Date |
User |
Action |
Args |
2020-03-30 15:13:56 | Mark.Shannon | set | recipients:
+ Mark.Shannon, methane |
2020-03-30 15:13:56 | Mark.Shannon | set | messageid: <1585581236.94.0.571794171265.issue40116@roundup.psfhosted.org> |
2020-03-30 15:13:56 | Mark.Shannon | link | issue40116 messages |
2020-03-30 15:13:56 | Mark.Shannon | create | |
|