Delegate perfomance (outrage was redherring)

bearophile bearophileHUGS at lycos.com
Fri Oct 16 00:52:00 PDT 2009


Justin Johansson:

> Also added -O switch this time though have no idea what level of optimization that does.
> (btw. In this test code, the -release switch doesn't do anything does it
> as that's just for conditional compilation?)

In DMD:
-O means "full optimizations minus the inlining (and keeping asserts, bound tests, contracts and maybe more).
-release means no asserts (but it keeps assert(0)), no bound tests and no contracts.
-inline means to perform inlining.
So generally when you care for performance you compile in DMD with: -O -release -inline
(But sometimes inlining makes the performance a little worse, because there's more pressure on the small code half of L1 cache).
In this program -release doesn't change the timings probably because there's nothing to remove (bound tests, etc).

In LDC:
-O equals to -O2, that means an average optimization.
-O3 means more optimization and includes two successive inlining passes (so foreach over an opApply are often fully simplified. But only few delegates/function pointers are inlined).
-O4 and -O5 currently mean -O3, in future (I hope soon!) -O4 will perform all the optimizations of -O3 plus link-time optimization and _Dmain interning (that's already doable, but only manually).
If you add -inline I think (but I am not sure) it performs a third inlining pass. 
There is the -release too that does as in DMD, plus flags for a finer releasing (for example to disable just asserts but not array bounds) that are not available in DMD.


>The results are not clear cut at all this time.  So what's going on?<

I don't know. I have a certain experience of benchmarks now, and I know they are tricky.

I usually like to help people understand they don't understand what's going on in their life, because they often have just an illusion of understanding things :-)

You may use something like obj2asm (or a disassembler) to see the asm produces in both cases, to understand a little better. If you don't have ways to do it, I can show you the resulting asm myself.

Bye,
bearophile



More information about the Digitalmars-d mailing list