Issue25949
Created on 2015-12-25 12:48 by serhiy.storchaka, last changed 2022-04-11 14:58 by admin. This issue is now closed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| odict___dict__.patch | serhiy.storchaka, 2015-12-25 12:48 | review | ||
| Messages (4) | |||
|---|---|---|---|
| msg256988 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * | Date: 2015-12-25 12:48 | |
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.
|
|||
| msg257044 - (view) | Author: Camilla Montonen (Winterflower) | Date: 2015-12-26 20:01 | |
Hi Serhiy, I tried to see whether the patch's unit test in test_ordered_dict.py would fail when the changes to odictobject.c were not applied and it did not. The code change to test_ordered_dict.py does not appear to test the fact that a dict is not automatically created when an ordered dict is instantiated (?). |
|||
| msg258593 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * | Date: 2016-01-19 13:56 | |
The patch have no visible effect, except lesser memory consumption. The latter is hard to measure in tests. Additional tests just ensure that the patch doesn't break existing behavior. |
|||
| msg259849 - (view) | Author: Roundup Robot (python-dev) | Date: 2016-02-08 14:39 | |
New changeset caab6b356a9e by Serhiy Storchaka in branch 'default': Issue #25949: __dict__ for an OrderedDict instance is now created only when https://hg.python.org/cpython/rev/caab6b356a9e |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:58:25 | admin | set | github: 70137 |
| 2017-04-25 01:18:03 | jcea | set | nosy:
+ jcea |
| 2016-02-08 14:40:06 | serhiy.storchaka | set | status: open -> closed resolution: fixed stage: patch review -> resolved |
| 2016-02-08 14:39:36 | python-dev | set | nosy:
+ python-dev messages: + msg259849 |
| 2016-01-19 13:56:45 | serhiy.storchaka | set | assignee: serhiy.storchaka messages: + msg258593 |
| 2015-12-26 20:01:16 | Winterflower | set | nosy:
+ Winterflower messages: + msg257044 |
| 2015-12-25 12:48:08 | serhiy.storchaka | create | |