[Python-ideas] Dict literal use for custom dict classes
Eric Snow
ericsnowcurrently at gmail.com
Thu Dec 17 14:57:42 EST 2015
On Thu, Dec 17, 2015 at 11:07 AM, Andrew Barnert <abarnert at yahoo.com> wrote:
> It seems like whatever the resolution of this discussion (unless it's "people mostly agree that X would be acceptable, doable, and probably desirable, but nobody's going to do it") you may want to rewrite and repush PEP 468.
Agreed. It's just a simple matter of finding time. <wink>
> IIRC, the one concern of Guido's that you couldn't answer was that if someone keeps the kwdict and adds to it, he could end up wasting a lot of space, not just time. If OrderedDict is still 150-200% bigger than dict, as in the pure Python version, that's still a problem.
Yeah, he said something like that. However, with the C implementation
the memory usage is less. Compared to dict:
* basically 8 extra pointers on the object [1]
* an instance __dict__
* an array of pointers equal in length to the underlying dict's hash table
* basically 4 pointers per item
So, per the __sizeof__ method, an empty C OrderedDict uses 800 bytes
in contrast to 280 bytes for dict. Each added item uses an additional
24 bytes. With 1000 items usage is 122720 bytes (compared to 49240
bytes for dict). With the pure Python OrderedDict, empty is 824
bytes, each item uses 152 bytes, and with 1000 items usage is 250744
bytes.
-eric
[1] https://hg.python.org/cpython/file/default/Objects/odictobject.c#l481
More information about the Python-ideas
mailing list