[Vm-dev] Direct object pointers vs indirect ones pros and cons

Levente Uzonyi leves at elte.hu
Fri Nov 12 13:24:55 UTC 2010


On Fri, 12 Nov 2010, Igor Stasenko wrote:

>
> Here a 'simulated' kind of indirect pointers.
>
> The Wrapper class having an 'object' ivar
> and in this way, we simulating indirection.
>
>
> | objects wrapped t1 t2 t3 |
> objects := (1 to: 1000) collect: [:i | Object new ].
> wrapped := objects collect: [:each | Wrapper new object: each ].
>
> t1 := [ 100000 timesRepeat: [ objects do:[ :each |  each yourself ] ]
> ] timeToRun.
> t2 := [ 100000 timesRepeat: [ wrapped do:[ :each |  each object
> yourself ] ] ] timeToRun.
> t3 := [ 100000 timesRepeat: [ wrapped do:[ :each |  ] ] ] timeToRun.
> {t1. t2. t3}
>
> Running on Cog it gives:
>
> #(3241 3498 2793)

Single measurement is probably inaccurate. This benchmark creates lots of 
blocks, which means GC noise. The size of the "object table" is too small 
to be realistic, this hides cache related performance hits. Why don't you 
use an Array instead of Wrapper? IIRC Cog has optimization for the #at: 
primitive, also Arrays are compact. Why do you send #yourself and 
#timesRepeat:? You should slightly shuffle the objects to be more 
realistic about cache usage.


Levente

>
> the first bench is kind-of 'measure time to access directly to objects'
> the second one is 'measure indirect access'
> and third is measure a loop overhead.
>
> So, by taking this naive benchmark, we got:
>
> (3498 - 2793) / (3241 - 2793) asFloat
> 1.573660714285714
>
> so, 50% slower.
>
> But actually this benchmarks shows a cost of extra message send rather
> than impact of extra level of indirection.
> Well, a message is a kind of indirection..  :)
>
> -- 
> Best regards,
> Igor Stasenko AKA sig.
>


More information about the Vm-dev mailing list