Associative Arrays need cleanout method or property to help

bearophile bearophileHUGS at lycos.com
Sat Mar 20 12:21:11 PDT 2010


Moritz Warning:
> The Python docs say that common usage is mostly about very small aas
> with frequent accesses but rare changes.

D and Python will probably have different usage patterns for AAs. In Python dicts (AAs) are used to give arguments to functions (that's why recursive functions are so slow in Python) and to represent most name spaces (there are few exceptions like the __slots__, but they are uncommon), so in a big percentage of cases they contain few string-value pairs (they have an optimization for string-only keys), that's why python dicts have an optimization for less than about 8 key-value pairs.

In D AA are easy to use so people will probably use smaller AAs compared to the AAs used in C++/Java, so I think a small-AA optimization can be useful in D too. But little AAs are not used for all those Python purposes, so probably on average they are going to be larger.

A way to know the usage patterns of D AAs is to add instrumentation in nonrelease mode, they can save few statistical data once in a while in the install directory of D, and then the user can give this little txt file to Walter to tune the language :-)

Bye,
bearophile



More information about the Digitalmars-d mailing list