[Python-Dev] Dictionary sparseness

Tim Peters tim@zope.com
Mon, 5 May 2003 15:34:58 -0400


[Tim]
>> the best thing a user can do is rebuild the dict from scratch,
>> inserting keys by decreasing order of access frequency.

[Raymond Hettinger]
> Then a periodic resize comes alongm re-inserting everything
> in a different order.

Sure -- micro-optimizations are always fragile.  This kind of thing will be
done by someone who's certain the dict is henceforth read-only, and who
thinks it's worth the risk and obscurity to get some small speedup.  They're
probably right at the time they do it, too, and probably wrong over time.
Same thing goes for, e.g., an madvise() call claiming a current truth that
changes over time.

> ...
> Does the *4 patch (amended to have an upper bound) have a chance?
> It's automatic, simple, benefits some cases while not harming others,

It would be nice if more people tried it and added their results to the
patch report:

    http://www.python.org/sf/729395

Right now, we just have Guido's comment saying that he no longer sees the
Zope3 startup speedup he thought he saw earlier.  Small percentage speedups
are like that, alas.  The patch is OK by me.