Reimplementing WeakKeyDictionary
Philippe Marschall
philippe.marschall at gmail.com
Sun Mar 18 15:07:01 UTC 2007
2007/3/18, "Martin v. Löwis" <martin at v.loewis.de>:
> I now have completed a first version of a reimplementation of
> WeakKeyDictionary, with the objective of improving performance
> (both computation and memory consumption). The entire change
> with a discussion can be seen at
>
> http://bugs.squeak.org/view.php?id=6348
>
> In essence, this introduces two changes:
> - when values are finalized or keys removed from the dictionary,
> it is not always rehashed anymore. Instead, the dictionary just
> releases the value, and marks the association as expired. Expired
> associations can then be reused if a new value is to be inserted
> under the same has. Rehashing is only done when so many entries
> have expired. Expired entries don't count towards the size of the
> dictionary, and aren't reported when iterating over the dictionary.
> - WeakKeyAssociation was rewritten to be a weak class, with a fixed
> slot for the value, and a weak slot for the key (currently, it
> has two fixed slots, with the key slot referring to a WeakArray
> of length 1).
>
> In some measurements involving large (10000 keys) or many (10000)
> small weak key dictionaries, this new implementation improves
> performance by a factor of 4..5, when measuring finalization time.
> The second change saves 8 bytes per association (on a 32-bit
> machine).
Could you attach the code for these stress tests to the bug?
Cheers
Philippe
> Regards,
> Martin
>
>
>
>
>
More information about the Squeak-dev
mailing list
|