Properties set/get huge speed difference?

Sean Kelly sean at f4.ca
Mon Oct 9 16:22:13 PDT 2006


Josh Stern wrote:
> On Mon, 09 Oct 2006 12:20:36 -0700, Sean Kelly wrote:
> 
> 
>>      void main() {
>>          C c = new C();
>>          c.doSomething(); // A
>>      }
>>
>> In the code above, even though a vtbl entry may be generated for 
>> doSomething, the compiler may optimize the call at point A by calling 
>> C.doSomething directly instead of using a double lookup through C's 
>> vtbl.  This can be accomplished because the compiler knows that c must 
>> be an instance of C at the call point (thus making the optimization 
>> extensible to more complex cases where doSomething really is a virtual 
>> function).  I'm not sure if DMD currently performs this optimization 
>> however, but my guess would be that it does not.  It's still more 
>> important to make DMD as bug-free as possible than it is to optimize 
>> corner-cases.
> 
> I had all the same thoughts.  For all these reasons, wouldn't it be a good
> idea to add "final" methods to the language to give the developer the
> necessary tool to optimize this intelligently if they need it?

Hrm... perhaps I'm misunderstanding, but don't they already exist?

     class C {
         final void doSomething() {}
     }

'final' guarantees that C.doSomething above will not have a vtbl entry.


Sean



More information about the Digitalmars-d-learn mailing list