[Python-Dev] Guarantee ordered dict literals in v3.7?

Paul Ganssle pganssle at gmail.com
Sun Nov 5 15:10:29 EST 2017

I think the question of whether any specific implementation of dict could be made faster for a given architecture or even that the trade-offs made by CPython are generally the right ones is kinda beside the point. It's certainly feasible that an implementation that does not preserve ordering could be better for some implementation of Python, and the question is really how much is gained by changing the language semantics in such a way as to cut off that possibility.

On 11/05/2017 02:54 PM, Serhiy Storchaka wrote:
> 05.11.17 21:30, Stefan Krah пише:
>> On Sun, Nov 05, 2017 at 09:09:37PM +0200, Serhiy Storchaka wrote:
>>> 05.11.17 20:39, Stefan Krah пише:
>>>> On Sun, Nov 05, 2017 at 01:14:54PM -0500, Paul G wrote:
>>>>> 2. Someone invents a new arbitrary-ordered container that would improve on the memory and/or CPU performance of the current dict implementation
>>>> I would think this is very unlikely, given that the previous dict implementation
>>>> has always been very fast. The new one is very fast, too.
>>> The modification of the current implementation that don't preserve
>>> the initial order after deletion would be more compact and faster.
>> How much faster?
> I didn't try to implement this. But the current implementation requires periodical reallocating if add and remove items. The following loop reallocates the dict every len(d) iterations, while the size of the dict is not changed, and the half of its storage is empty.
> while True:
>     v = d.pop(k)
>     ...
>     d[k] = v
> _______________________________________________
> Python-Dev mailing list
> Python-Dev at python.org
> https://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe: https://mail.python.org/mailman/options/python-dev/paul%40ganssle.io

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: OpenPGP digital signature
URL: <http://mail.python.org/pipermail/python-dev/attachments/20171105/934b8106/attachment.sig>

More information about the Python-Dev mailing list