Virtual methods

bearophile bearophileHUGS at
Wed Feb 3 14:28:05 PST 2010

Walter Bright:

> The virtual function calls are the calls to 
> Internal.walkSum() via an expression typed as Node.walkSum().

That expression typed as Node.walkSum() also calls Leaf.walkSum().

> The Java 
> JIT has access to the entire program, so it can do whole program 
> analysis and determine that the *only* instances of Node that ever exist 
> are actually instances Internal,

There are Leaf instances too.

> So why doesn't D do it? Because D's optimization runs when compiling a 
> module. It does not have access to the whole program,

With LDC you can use a level of optimization (LTO) that spans all the modules you are compiling at once. There are times when you want to optimize a final release of a program as well as possible.
And anyway, this whole benchmark program is made of a single little module.

> However, if you change the types of left and right from Node to 
> Internal,

I can't, because there is are the Leaf objects too.

Thank you, bye,

More information about the Digitalmars-d mailing list