[Python-ideas] Dict literal use for custom dict classes

Nathaniel Smith njs at pobox.com
Thu Dec 17 00:36:19 EST 2015


On Wed, Dec 16, 2015 at 9:12 PM, Andrew Barnert <abarnert at yahoo.com> wrote:
> On Dec 16, 2015, at 15:17, Nathaniel Smith <njs at pobox.com> wrote:
>>
>>> On Wed, Dec 16, 2015 at 10:47 AM, Mike Miller <python-ideas at mgmiller.net> wrote:
[...]
>> That's not so clear, actually! It turns out that PyPy was able to make
>> their regular 'dict' implementation ordered, while at the same time
>> making it faster and more memory-efficient compared to their previous
>> (CPython-like) implementation:
>>
>>  http://morepypy.blogspot.com/2015/01/faster-more-memory-efficient-and-more.html
>>
>> So in PyPy all these issues are automatically solved for free. The
>> $1e6-question these other proposals have to answer is, why not do what
>> PyPy did?
>
> You don't even need that; a dict that's ordered as long as you never delete from it or expand it after initial creation is good enough, and that may be simpler. (For example, Raymond Hettinger's two-table prototype guarantees this much, even though it isn't order-preserving on deletes, and it should be faster and more compact than the current design, although I don't know if anyone's proven that part, and it's the "dead-simple once you see it" kind of brilliant rather than the deep-magic kind.)

IIUC, the PyPy dict is exactly a fully-worked-out version of Raymond
Hettinger's two-table design, and they claim that it is in fact faster
and more compact than the current design, so I suppose one could argue
that someone has indeed proven that part :-).

-n

-- 
Nathaniel J. Smith -- http://vorpus.org


More information about the Python-ideas mailing list