Accessing variables through sending messages

Andreas Raab andreas.raab at gmx.de
Tue Jun 21 19:37:36 UTC 2005


Alexandre Bergel wrote:
> Sorry to not have given more information about what I try to achieve.
> I have been working on adding state to traits. The idea is that the offset for a variable is not constant anymore. For instance, let's assume the following:
> 
> T1 defines v1			"offset of v1 = 1"
> T2 defines v2			"offset of v2 = 1"
> T3 uses T2 + T1 		"offset of v2 = 1 and v1 = 2"

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

[*] And this is starting to look a *lot* like Tweak ;-)

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

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. A really dumb little 
test (not that useful but just to get a gross feeling for the situation) 
seems to indicate that the difference is nowhere near the general 
send/bytecode difference:

a) [1 to: 10000000 do:[:i| ]] timeToRun.
	=> ~500 msecs

b) [1 to: 10000000 do:[:i| a := b + c]] timeToRun.
	=> ~700 msecs

c) [1 to: 10000000 do:[:i| a := self b + self c]] timeToRun.
	=> ~1500 msecs

d) [1 to: 10000000 do:[:i| self a: self b + self c]] timeToRun.
	=> ~2880 msecs

Note the dramatic relative increase between c) and d) which I believe is 
caused by the activation required for the mutator. But it looks like 
we're not getting anywhere near the theoretical 30x difference in speed 
and clearly there is no 1000x slowdown anywhere in sight ;-)

Please say more about this - I'm interested in this for obvious reasons.

Cheers,
   - Andreas



More information about the Squeak-dev mailing list