Accessing variables through sending messages

Colin Putney cputney at wiresong.ca
Tue Jun 21 20:12:06 UTC 2005


Alexandre Bergel wrote:

> 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).

Andreas Raab responded:

> Really? What benchmark are you using? Given that a) sends are roughly 
> 30x slower than byte codes (which is a loooong ways from 1000x slower) 
> and that b) accessors do not require activations (which makes the 
> difference a looooot less than the above factor of 30x) there doesn't 
> seem to be a good reason for it being 1000x slower. 

I haven't seen Alex's code, but 1000x doesn't sound far fetched. If he's 
using #instVarNamed: it's more than just sending an accessor. It's a 
send with a full activation, which does several more full sends to ask 
the class for the names of its instance variables, iterate over them 
checking for equality, then call the primitive to fetch the value based 
on index. Slooow.

I'm liking the sound of Tweak's approach here. I imagine it's the kind 
of thing that Exupery could optimize nicely, so it could perform very 
well, but it would also be more dynamic than the current offset-based 
system.

Colin




More information about the Squeak-dev mailing list