[squeak-dev] [Pharo-dev] Why do we have SmallDictionary?

Esteban Lorenzano estebanlm at gmail.com
Fri Jun 8 06:56:55 UTC 2018


Hi, 

it was supposed to be optimised for small sizes so I guessed it was about your choice of 100000 elements, but a fast benchmark with small numbers didn’t offered better results. 

So question is appropriate. 
Why we have it? 
Or better: why SmallDictionary is not faster?
Even better: is this test good? :)

cheers,
Esteban

> On 8 Jun 2018, at 08:46, Max Leske <maxleske at gmail.com> wrote:
> 
> Hi,
> 
> I was messing around with SmallDictionary when I suddenly realised that I can't find a single reason to use it over a normal Dictionary. While its name and class comment imply that it is somehow an optimised Dictionary, I don't see any measurement where that actually holds up. The following was run in a Pharo 7 image on a recent VM (see below):
> 
> | d |
> d := SmallDictionary new.
> d sizeInMemory. "24"
> [100000 timesRepeat: [
> 	1 to: 100 do: [ :i | d at:i put: i] ] ] timeToRun. "0:00:00:05.226"
> 
> [100000 timesRepeat: [
> 	d at: 48 ifAbsent: [] ] ] timeToRun. "0:00:00:00.041"
> 
> 
> 
> | d |
> d := Dictionary new.
> d sizeInMemory. "16"
> [100000 timesRepeat: [
> 	1 to: 100 do: [ :i | d at:i put: i] ] ] timeToRun. "0:00:00:00.385"
> [100000 timesRepeat: [
> 	d at: 48 ifAbsent: [] ] ] timeToRun.  "0:00:00:00.006"
> 
> 
> As you can see, SmallDictionary is 8 bytes larger per instance and significantly faster while reading and writing (I know that this isn't a good benchmark but it suffices to make my point).
> 
> 
> Is anyone aware of a reason for hanging on to SmallDictionary? I'm also curious to know how SmallDictionary came to be. There must have been some advantage over Dictionary at some point in the past.
> 
> 
> Cheers,
> Max
> 
> 
> 
> 
> 
> Image version: Pharo 7.0
> Build information: Pharo-7.0+alpha.build.961.sha.a69e72a97136bc3f93831584b6efa2b1703deb84 (32 Bit)
> 
> VM version: CoInterpreter VMMaker.oscog- nice.2281 uuid: 4beeaee7-567e-1a4b-b0fb-bd95ce302516 Nov 27 2017
> StackToRegisterMappingCogit VMMaker.oscog-nice.2283 uuid: 2d20324d-a2ab-48d6-b0f6-9fc3d66899da Nov 27 2017
> VM: 201711262336 https://github.com/OpenSmalltalk/opensmalltalk-vm.git $ Date: Mon Nov 27 00:36:29 2017 +0100 $ Plugins: 201711262336 https://github.com/OpenSmalltalk/opensmalltalk-vm.git $
> 
> OS: macOS 10.13.5
> Machine: MacBook Pro (13-inch, 2016, Four Thunderbolt 3 Ports)
> 



More information about the Squeak-dev mailing list