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

M.-A. Lemburg mal at egenix.com
Fri Oct 29 10:51:54 CEST 2010

Antoine Pitrou wrote:
> 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.

Are you sure ? In the age of GB RAM, runtime performance appears
to be more important than RAM usage. Moving the hash comparison out
of the dict would likely cause (cache) locality to no longer trigger.

> (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)

Marc-Andre Lemburg

Professional Python Services directly from the Source  (#1, Oct 29 2010)
>>> Python/Zope Consulting and Support ...        http://www.egenix.com/
>>> mxODBC.Zope.Database.Adapter ...             http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ...        http://python.egenix.com/

::: Try our new mxODBC.Connect Python Database Interface for free ! ::::

   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
    D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
           Registered at Amtsgericht Duesseldorf: HRB 46611

More information about the Python-ideas mailing list