Re:The cost of dynamic vs. static dispatch in C++ (2013)
by twoodfin on Saturday February 28, 2015 @03:35PM
(#9124945)
As the article demonstrates, in anything other than trivial microbenchmarks it's the inability to inline across a virtual call that will cost you. Inlining is the single most fundamental optimization for a modern C++ compiler. It enables the 0-cost abstractions for which C++ is rightly famous.
[ Parent
| on HN ]
Re:The cost of dynamic vs. static dispatch in C++ (2013)
by MichaelGG on Saturday February 28, 2015 @05:59PM
(#9125374)
Why shouldn't it be possible to inline virtual calls? The CLR folks were complaining about this, too. But it seems rather straightforward to figure out the actual implementation that's commonly called and inline it, perhaps with a guard for uncommon cases. And I wouldn't be surprised if many apps end up with only a single actual implementation, so the entire virtual overhead can just be dropped.
Re:The cost of dynamic vs. static dispatch in C++ (2013)
by adrusi on Saturday February 28, 2015 @06:31PM
(#9125451)
Because c++'s type system doesn't make it possible to determine the actual implementation in most cases. Concepts would allow rust-style monomorphization, but they aren't part if the standard yet.
Re:The cost of dynamic vs. static dispatch in C++ (2013)
by kazinator on Saturday February 28, 2015 @08:30PM
(#9125688)
None of this matters if you create the "flexible joints" in the right places, where you get the benefit of dispatch, without making hundreds of millions of calls per second to it.
Re:The cost of dynamic vs. static dispatch in C++ (2013)
by coliveira on Saturday February 28, 2015 @06:26PM
(#9125437)
The problem is that unlike the CLR, static compilers have no idea about the common case. This technique works only when you have some information about how the different code paths are being used.
Re:The cost of dynamic vs. static dispatch in C++ (2013)
by kazinator on Saturday February 28, 2015 @08:27PM
(#9125682)
Some virtual calls cannot be converted to static calls and inlined, because dynamic dispatch solves a problem which static calls do not solve. In that case, it is a bicycle versus canoe comparison.
C++ does a good job of inlining those calls to virtual functions that can be inlined: like when a virtual is invoked on an object whose exact type is obvious from the scope.