Properties set/get huge speed difference?

Sean Kelly sean at
Mon Oct 9 12:20:36 PDT 2006

Lars Ivar Igesund wrote:
> %u wrote:
>>> although the program compiled with dmd is slower (0.20s) than gdc, this
>>> doesn't concern me now. "final" works in dmd, both gets/sets have the
>>> same speed.
>> I thought D was supposed to automatically make all methods final that
>> aren't changed by a subclass?
> How could the compiler know that? The class might be put into a library, and
> subclassed in an application (a very common use case) or other library.

I think it's more likely that a compiler may optimize function calls 
when it knows exactly what type of object is being called.  For example:

     class C {
         void doSomething() {}

     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 


More information about the Digitalmars-d-learn mailing list