On 2010-08-21, at 15:56, Max Carlson wrote:

> On 8/21/10 12:24 PM, P T Withington wrote:
>> Not approved:
>> 
>> 1) I don't understand the point of this (which you have done in any number 
>> of places):
>> 
>>> (expr&&  (expr is LzAttributeDescriptor)
> >
>> that would just seem to add a redundant test.  if `expr` is null, it is not 
>> going to be an LzAttributeDescriptor, so why add another conditional?
> 
> I did this because the inlined is operator (in DHTML at least) is inefficient:
> 
> It was expanding to:
> if(LzAttributeDescriptor["$lzsc$isa"]?LzAttributeDescriptor.$lzsc$isa($8):$8 
> instanceof LzAttributeDescriptor){
> 
> Testing for null saves some work:
> if($8&&(LzAttributeDescriptor["$lzsc$isa"]?LzAttributeDescriptor.$lzsc$isa($8):$8
>  instanceof LzAttributeDescriptor)){
> 
> I guess I'll change the compiler's inlining instead of hacking the source.

Are there really that many null arguments that this makes a difference?  Surely 
that must be in the noise level?  If you change the compiler, then you are 
going to insert this extra test everywhere, which will be a dis-optimization 
for every time the LHS of `is` is not null.

If you really want to improve the compiler, then teach it how to read the 
meta-information from the LFC and learn at compile time whether a type has an 
`isa` method or not (only applies to types with mixins).  Then it can emit the 
correct code at compile time and not need the conditional expression at all.

>> 2) This can't work in as3, can it?  I really don't like cheating like this...
>> 
>>> +          // play a little fast and loose - if we have a .ready slot, 
>>> assume we're an event.
>>> +          if (thisevent) {
>>> +            if (thisevent.ready) { thisevent.sendEvent( args[ key ] ); }
> 
> It seems to be fine, at least with all the sample apps.  I don't like 
> cheating either, but it does shave off a tiny bit of time...

In my experience, micro-optimizations like this, which are only 'loosely' 
correct, will come back to bite you in the long run.  It is better to give up a 
CPU cycle and get the correct answer.

I am all for optimization, but not over-optimization.  Remember the golden 
rules of optimization:

1) Don't do it.

2) [For experts only]  Don't do it yet.

:P

Reply via email to