Re: IdentityKeyValueDictionary vs IdentityDictionary?
Reading the class comments of the two classes and poking around
in the implementation, it looks like IdentityKeyValueDictionary
does not use associations when adding entries to the dictionary
and IdentityDictionary creates associations ... so i seems that
adding entries would always be more expensive for
On 3/8/17 10:51 AM, Mariano Martinez
Peck via Glass wrote:
I was measuring performance of different dictionary classes
for a given scenario and I still cannot understand the
difference between IdentityDictionary
For this particular case (where I was measure #at:put:) the
later was much faster. Is that always the case? Because I
normally use IdentityDictionary everywhere for identity based
The Association instances of IdentityDictionary make additions slower. There are usage patterns where ID can be faster and better. If used as a root collection that others share and update (existing keys) then ID would have less chance of commit conflict (sometimes only same-key modifications would conflict). IKVD is faster for collections that are mostly added to by one session.
Page costs can be another performance difference (and tuning opportunity). IKVD would use fewer pages and keys and values would (by default) tend to be co-located. You could cluster keys structures separate from values structures to favor some access patterns. With ID you'd be able to cluster-tune with association instances but key-value pair references would always be co-located. Consider that a rehash of a collection can keep the same Association instances and so it is possible to cluster-tune ID associations for fewer page changes upon regrowth.
IKVD is not always faster and initial performance gains can have hidden every-day usage costs later. Know where each can better.
Whenever practical use #new: to create pre-grown collection instances. GS grows indexable collections exceptionally quickly, and so some collections will use #new anyway. [Advanced tip] You can modify #new: of one of the collections (I forget which, but likely a subclass of SequenceableCollection) to get much better performance by actually pregrowing.
Another advanced tip is that using #size: to 0 improves GC performance when you know you no longer need a collection. Unfortunately not all the GS collections do the most efficient resize to empty. I found big improvements by implementing something named like #resizeEmpty to do the most efficient (and polymorphic) assistive cleanup.
On Mar 8, 2017 1:51 PM, "Mariano Martinez Peck via Glass" <[hidden email]> wrote:
I was measuring performance of different dictionary classes for a given scenario and I still cannot understand the difference between IdentityDictionary and IdentityKeyValueDictionary.
For this particular case (where I was measure #at:put:) the later was much faster. Is that always the case? Because I normally use IdentityDictionary everywhere for identity based dictionaries.