Serhiy Storchaka <storchaka+cpyt...@gmail.com> added the comment:

There are several common idioms which do not work well with shared dictionaries.

1. Class attributes as defaults. If most instances of the class have the 
default value for some attribute, it can be set as the class attribute. It 
saves memory because most instances will have smaller dict. But if the first 
instance has such attribute, it cancels shared dict for all following instances 
without this attribute.

2. cached_property (and analogs). The cached instance attributes can be added 
in arbitrary order, canceling shared dict for this instance and maybe for all 
instances created later.

3. Some classes delete attributes in close() or __exit__() methods to avoid 
reference loops and to release resources earlier. Since shared dicts do not 
support deletion, such closed objects have now larger size than non-closed 
objects.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue40116>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to