[squeak-dev] Letting Set contain nils?

bryce at kampjes.demon.co.uk bryce at kampjes.demon.co.uk
Sat Aug 9 14:26:14 UTC 2008


Eliot Miranda writes:

 > Depends.  In an Interpreter obj == self likely to be slightly faster than
 > obj == nil since nil must be fetched either form the specialObjectsArray (if
 > bytecode set has pushNl, as it does) or from the method's literal frame.  In
 > a JIT they're liely the same because self is a read through the frame
 > pointer and nil is a constant embedded in the instruction stream.  These are
 > likely to be of similar cost.
 > 
 > obj isNil will either be the same cost as == nil or slower depending on
 > whether the bytecode compiler inlines it.
 > But the difference between obj == self & obj == nil/obj isNil will be in the
 > noise.
 > 
 > You should make the decision on convenience.
 > 
 > what is faster/slower?
 > 
 > 
 > anArray asSet size is faster than any of the alternatives because it is
 > easier to thunk about ;)  Faster thought is much more valuable than faster
 > processing, c.f. Smalltalk programs vs C++ programs ;)

In Exupery at the moment obj == self is likely to be the fastest as
self is held in a register. obj == nil would involve going to either
the method's literal frame or the special object array.  Exupery
doesn't hold direct references to objects in native code outside of
it's PICs, this is to simplify interaction with the GC.

But it's possible to add reasonably generic optimisations that make
other versions as fast. Don't worry too much about it, unless you
really need the speed, then benchmark yourself. 

Bryce



More information about the Squeak-dev mailing list