[Python-ideas] dict changes [was: Ordered storage of keyword arguments]

Antoine Pitrou solipsis at pitrou.net
Fri Oct 29 00:11:51 CEST 2010

Le jeudi 28 octobre 2010 à 14:44 -0400, Jim Jewett a écrit :
> For a string dict, that hash should already be available on the string
> object itself, so it is redundant.  Keeping it obviously improves
> cache locality, but ... it also makes the dict objects 50% larger, and
> there is a chance that the strings themselves would already be in
> cache anyhow.  And if strings were reliably interned, the comparison
> check should normally just be a pointer compare -- possibly fast
> enough that the "different hash" shortcut doesn't buy anything.
> [caveats about still needing to go to the slower dict implementation
> for string subclasses]

I've thought about that. The main annoyance is to be able to switch
transparently between the two implementations. But I think it would be
interesting to pursue that effort, since indeed dicts with interned keys
are the most common case of dicts in the average Python workload. Saving
1/3 of the memory size on these dicts would be worthwhile IMO.

(addressing itself would perhaps be a bit simpler, because of
multiplying by 8 or 16 instead of multiplying by 12 or 24. But I doubt
the difference would be noticeable)



More information about the Python-ideas mailing list