4 ms·
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 t
by twoodfin 12y ago
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.
- MichaelGG 12y agoWhy 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.
- coliveira 12y agoThe 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.
- adrusi 12y agoBecause 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.
- kazinator 12y agoNone 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.
- deleted 12y ago[deleted]
- kazinator 12y agoSome 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.