[Pharo-dev] Understanding WeakValueDictionary

Norbert Hartl norbert at hartl.name
Thu Apr 17 10:35:12 EDT 2014

Am 17.04.2014 um 16:06 schrieb Igor Stasenko <siguctua at gmail.com>:

> On 17 April 2014 10:26, Norbert Hartl <norbert at hartl.name> wrote:
> While looking at the code in voyage I got to WeakValueDictionary as voyage uses it as object cache. If I looked correctly the WeakValueDictionary is based on equality and not identity. Is that correct? Feels wrong!
> well, comparison used for keys.. 
> and i agree that for caching, an identity comparison makes much more sense,
> since you want it to be fast, and identity comparison is no doubt faster than
> equality comparison, especially if keys are complex objects which implement equality based on comparing own fields.
Agreed. But I think that equality based comparison is not only slower but wrong! Implementing an object cache based on equality can easily screw up your graph. You can call it the crappiest kind of become: you’ve never wanted!

> but for that, i think we would need new kind of dictionary, e.g.
> WeakValueIdentityKeyDictionary (or some similar name).  

> Btw, for caching i prefer to use round-robin cache with limited size

You mean those things where you can state: „Hey, I’m fast because I exchanged * with + ?“ :)


> (like that cache never grows too big, and instead simply drops/overrides existing entries when it become full).. this helps maintaining cache size under control. 
> A good example is LRUCache, which is very suitable method to cache objects.. albeit at cost of some extra processing for accessing it. 
> Norbert
> -- 
> Best regards,
> Igor Stasenko.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.pharo.org/pipermail/pharo-dev_lists.pharo.org/attachments/20140417/a3170e8e/attachment-0002.html>

More information about the Pharo-dev mailing list