Feature Request: nontrivial functions and vtable optimizations

Craig Black craigblack2 at cox.net
Thu Aug 14 20:01:59 PDT 2008


"Jb" <jb at nowhere.com> wrote in message news:g7ubhk$2hq5$1 at digitalmars.com...
>
> "Craig Black" <cblack at ara.com> wrote in message 
> news:g7s7o1$dpt$1 at digitalmars.com...
> (on x86 anyway).
>
> Virtual methods are in such high use that Intel and Amd have put a lot of 
> effort into optimizing them.
>
> Replacing the function pointer with a conditional branch wont make it 
> faster.

It may or may not improve performance.  Depends on the particular case.

>> See Microsoft Visual C++ profile guided optimizations (PGO) "Virtual Call 
>> Speculation". Using PGO, the most commonly called virtual functions are 
>> optimized so that they do not require a function pointer invokation.
>
> The speedup you get from this is the inlining of the function, *not* the 
> getting rid of the function pointer lookup. It still requires a lookup in 
> the class info and a conditional branch to check that the "inlined 
> function" is the correct match for the speculated object.
>
> That will still cost a whole pipline of cycles if wrongly predicted.

You may be right in some cases.  Profile to be sure.  But experience has 
taught me to be wary of function pointer invokations, even on modern CPU's. 
If you want to believe that there is never a penalty for function pointer 
invokation go right ahead.  After all, it's only two instructions right? 
Must be real fast. ;)

-Craig 




More information about the Digitalmars-d mailing list