Movatterモバイル変換


[0]ホーム

URL:


homepage

Issue25949

This issue trackerhas been migrated toGitHub, and is currentlyread-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title:Lazy creation of __dict__ in OrderedDict
Type:enhancementStage:resolved
Components:Extension ModulesVersions:Python 3.6
process
Status:closedResolution:fixed
Dependencies:Superseder:
Assigned To: serhiy.storchakaNosy List: Winterflower, eric.snow, jcea, python-dev, rhettinger, serhiy.storchaka
Priority:normalKeywords:patch

Created on2015-12-25 12:48 byserhiy.storchaka, last changed2022-04-11 14:58 byadmin. This issue is nowclosed.

Files
File nameUploadedDescriptionEdit
odict___dict__.patchserhiy.storchaka,2015-12-25 12:48review
Messages (4)
msg256988 -(view)Author: Serhiy Storchaka (serhiy.storchaka)*(Python committer)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)*(Python committer)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)(Python triager)Date: 2016-02-08 14:39
New changesetcaab6b356a9e by Serhiy Storchaka in branch 'default':Issue#25949: __dict__ for an OrderedDict instance is now created only whenhttps://hg.python.org/cpython/rev/caab6b356a9e
History
DateUserActionArgs
2022-04-11 14:58:25adminsetgithub: 70137
2017-04-25 01:18:03jceasetnosy: +jcea
2016-02-08 14:40:06serhiy.storchakasetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2016-02-08 14:39:36python-devsetnosy: +python-dev
messages: +msg259849
2016-01-19 13:56:45serhiy.storchakasetassignee:serhiy.storchaka
messages: +msg258593
2015-12-26 20:01:16Winterflowersetnosy: +Winterflower
messages: +msg257044
2015-12-25 12:48:08serhiy.storchakacreate
Supported byThe Python Software Foundation,
Powered byRoundup
Copyright © 1990-2022,Python Software Foundation
Legal Statements

[8]ページ先頭

©2009-2026 Movatter.jp