dcollections 1.0 and 2.0a beta released

bearophile bearophileHUGS at lycos.com
Thu May 20 12:47:22 PDT 2010


Michel Fortin:

>Devirtualization is only possible in certain cases: when the function knows exactly which type it'll get.<

You are wrong, in most cases there are ways to de-virtualize, even when the runtime type isn't exactly known, but sometimes to do it you have to work too much. This is probably why C# dotnet doesn't perform this optimization.

It's a complex topic, I suggest you to read about it, I can't explain here, see polymorpic call points, megamorphic ones, dispatch trees, and so on.

You can read something here too:
http://www.digitalmars.com/webnews/newsgroups/newsgroups.php?art_group=digitalmars.D&article_id=105630

LLVM is not able to do this yet well, but once the -O7 optimization level is available it will have the means (if not the capability) to devirtualize as well as HotSpot:
http://linux.die.net/man/1/llvmc
And even if you don't compile your code with -O7 there are ways to improve the situation anyway with static code analysis (but usually this is not as good as type information collected at runtime or during profiling for profile-based optimization).


>Indeed. I'm no expert in linkers, but in my opinion this is one of the most basic optimizations a linker should perform.<

At its basic level it's an easy optimization, but as usual if you want to implement something well, things gets harder :-)
In LDC it's the compiler that is performing this optimization, and only if you manually add the -mergefunc switch, that is not used even in -O3.


>The problem with templates are more the multiple slightly different instanciations.<

This is what I was talking about with things getting "harder". A good implementation of this feature can recognize slightly different functions too, and remove such partial redundancy. This is doable, but LLVM is not able to do this yet. The good thing is that LLVM is improving quickly still.


>In general this is good for performance, but it's only needed for the code paths that need to be fast. I think generic containers should be fast.<

I am not sure what you mean here, but you can be interested in this thread started by me:
http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=108136

Bye,
bearophile


More information about the Digitalmars-d-announce mailing list