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 serhiy.storchaka
Recipients eric.snow, rhettinger, serhiy.storchaka
Date 2015-12-25.12:48:07
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1451047688.41.0.0988158472157.issue25949@psf.upfronthosting.co.za>
In-reply-to
Content
For now OrderedDict always creates an empty dict for __dict__.

>>> from collections import OrderedDict
>>> import gc
>>> gc.get_referents(OrderedDict())
[{}]
>>> class OD(OrderedDict): pass
... 
>>> gc.get_referents(OD())
[<class '__main__.OD'>, {}]

But dict subclasses (as well as most other classes) create an empty dict for __dict__ only if needed.

>>> class D(dict): pass
... 
>>> d = D()
>>> gc.get_referents(d)
[<class '__main__.D'>]
>>> d.__dict__
{}
>>> gc.get_referents(d)
[{}, <class '__main__.D'>]

This allows to save CPU time for dictionary creation and a memory (144 bytes on 32-bit, twice as much on 64-bit).

Proposed patch makes __dict__ in OrderedDict to be created only if needed.
History
Date User Action Args
2015-12-25 12:48:08serhiy.storchakasetrecipients: + serhiy.storchaka, rhettinger, eric.snow
2015-12-25 12:48:08serhiy.storchakasetmessageid: <1451047688.41.0.0988158472157.issue25949@psf.upfronthosting.co.za>
2015-12-25 12:48:08serhiy.storchakalinkissue25949 messages
2015-12-25 12:48:08serhiy.storchakacreate