Accessing variables through sending messages

Alexandre Bergel bergel at iam.unibe.ch
Wed Jun 22 08:52:34 UTC 2005


> This looks like premature static optimization for me. What's wrong with 
> just using messages? E.g., if all references to v1 and v2 are compiled 
> into message sends (something the compiler can do trivially [*]) you can 
> define the "offset" in any way you like in the leaf class (T3).

My first goal was to avoid having accessors to access variable. But you're right, this might probably be the way to go.


> >Currently I use the instVarName to access variable (note that I prefixed
> > them like T1.v1). I have a running implementation, but accessing variable
> > in this way is quite slow (about 1000 times slower).

I was comparing using direct variable access and using reflection through instVarNamed:
However, when I measure this access again I obtain:
o := Time now.
Time millisecondsToRun: [1 to: 100000 do: [:i| o asSeconds]]. 
==> 23
Time millisecondsToRun: [1 to: 100000 do: [:i| o instVarNamed: 'seconds']]. 
==> 1968

Which is about 85 times slower.


you are right, probably we will go for generating accessor/mutator for each variable access.

Cheers,
Alexandre

-- 
_,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:
Alexandre Bergel  http://www.iam.unibe.ch/~bergel  
^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;.




More information about the Squeak-dev mailing list