[Pharo-dev] String >> #=

Philippe Marschall philippe.marschall at netcetera.ch
Tue May 27 09:54:00 EDT 2014


On 26.05.14 09:51, Philippe Marschall wrote:
> Hi
>
> I have been investigating why Dictionary look up performance with String
> keys is not as good as I would expected. Something I noted is that
> String >> #= is implemented in terms of #compare:with:collated:. There
> is no short circuit if Strings are not the same size. In my case some
> Strings have the same prefix but a different length eg 'Content-Type'
> and 'Content-Length'. In that case a #compare:with:collated: is
> performed even though we know in advance the answer will be false
> because they have different sizes.

Some follow up on this:
In Seaside we have a custom dictionary GRSmallDictionary which is more 
or less an OrderedCollection of Associations (not actually but 
conceptually). I did a microbenchmark with 11 keys [1] and out of the 
box Dictionary is about twice as fast as GRSmallDictionary. However when 
I change GRSmallDictionary to first send and compare #size before 
sending #= then GRSmallDictionary is slightly faster than Dictionary.

  [1] #('Content-Type' 'Content-Language' 'Content-Length' 'Date' 
'Last-Modified' 'Location' 'Set-Cookie' 'Set-Cookie2' 'Servlet-Engine' 
'Status' 'WWW-Authenticate')

Cheers
Philippe






More information about the Pharo-dev mailing list