[issue40116] Regression in memory use of shared key dictionaries for "compact dicts"

Raymond Hettinger report at bugs.python.org
Wed Sep 22 15:02:33 EDT 2021


Raymond Hettinger <raymond.hettinger at gmail.com> added the comment:

> Overall, I expect the improved sharing to more than
> compensate for the disadvantages.

I expect the opposite.  This makes all dicts pay a price (in space, initialization time, and complexity) for a micro-optimization of an uncommon case (the normal case is for __init__ to run and set all the keys in a consistent order).  It is unlikely that the "benefits" to never be felt in real-word applications, but "disadvantages" would affect every Python program.

> The language specification says that the dicts maintain insertion 
> order, but the wording implies that this only to explicit 
> dictionaries, not instance attribute or other namespace dicts.

That is a quite liberal reading of the spec.  I would object to making instance and namespace dicts behave differently.  That would be a behavior regression and we would forever have to wrestle with the difference.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue40116>
_______________________________________


More information about the Python-bugs-list mailing list