[Python-Dev] PEP for new dictionary implementation

Mark Shannon mark at hotpy.org
Sat Feb 11 22:22:01 CET 2012


Antoine Pitrou wrote:
> Hello Mark,
> 
> I think the PEP should explain what happens when a keys table needs
> resizing when setting an object's attribute.

If the object is the only instance of a class, it remains split,
otherwise the table is combined.
Most OO code will set attributes in the __init__ method so all 
attributes are set before a second instance is created.
For more complex use patterns, it is impossible to know what is the
best approach, so the implementation allows extra insertions up to the 
point of a resize when it reverts to the combined table (non-shared keys).
(This may not be the case in the bitbucket repository,
I'll push the newer version tomorrow).

> Reading the implementation, it seems the sharing can disappear
> definitely, which seems a bit worrying.

It is immediately re-split (to allow sharing) when only one instance of 
the class exists.
I've implemented it that way (resize->combined then re-split) as most 
resizes (999 out of 1000) will be of combined tables, and I don't want 
to complicate the fast path.

Cheers,
Mark.


More information about the Python-Dev mailing list