[Python-Dev] Dictionary sparseness

Agthorr agthorr@barsoom.org
Mon, 5 May 2003 13:14:16 -0700


On Mon, May 05, 2003 at 03:34:58PM -0400, Tim Peters wrote:
> 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.  

An alternate optimization would be the additional of an immutable
dictionary type to the language, initialized from a mutable dictionary
type.  Upon creation, this dictionary would optimize itself, in a
manner similar to "gperf" program which creates (nearly) minimal
zero-collision hash tables.

On this plus side, this would form a nice symmetry with the existing
mutable vs immutable types.

Also, it would be proof against bit-rot, since either:
 a) the user changes the mutable dictionary before it is optimized.
    In this case, the optimizer will simply optimize the new
    dictionary, or
 b) the user attempts to modify the immutable dictionary, which will
    fail with an error.

-- Agthorr