News for hackers. Stuff that matters.
Re:The Performance Impact of C++'s `final` Keyword by account42 on Tuesday April 23, 2024 @07:23AM (#40130592)
> Devirtualization helps performance because you are able to benefit from inheritance and not have to pay a performance penalty for that. Without the final keyword, a performance oriented project would need to be architected to not use inheritance at all, or in the very least in code in the hot path, because that sneaks gratuitous pointer dereferences all over the place, which require running extra operations and has a negative impact on caching.

virtual inheritance. Regular old inheritance does not need or benefit from devirtualization. This is why the CRTP exists.

Re:The Performance Impact of C++'s `final` Keyword by chipdart on Tuesday April 23, 2024 @07:50AM (#40130822)
> This is why the CRTP exists.

CRTP does not exist for that. CRTP was one of the many happy accidents in template metaprogramming that happened to be discovered when doing recursive templates.

Also, you've missed the whole point. CRTP is a way to rearchitect your code to avoid dereferencing pointers to virtual members in inheritance. The whole point is that with final you do not need to pull tricks: just tell the compiler that you don't want the class to be inherited, and the compiler picks up from there and does everything for you.

Re:The Performance Impact of C++'s `final` Keyword by account42 on Tuesday April 23, 2024 @08:35AM (#40131221)
If that's your point then it is simply wrong. Final does not allow the compiler to devirtualize calls through a base pointer, it only eliminates the virtualness for calls through pointers to the (final) derived type. The compiler can devirtualize calls through base pointers in others ways (by deducing the possible derived types via whole program optimization or PGO) but final does not help with that.
Re:The Performance Impact of C++'s `final` Keyword by chipdart on Tuesday April 23, 2024 @10:41AM (#40132530)
> If that's your point then it is simply wrong. Final does not allow the compiler to devirtualize calls through a base pointer, it only eliminates the virtualness for calls through pointers to the (final) derived type.

Please read my post. That's not my claim. I think I was very clear.

Re:The Performance Impact of C++'s `final` Keyword by scaredginger on Tuesday April 23, 2024 @03:11PM (#40135944)
Maybe a nitpick, but virtual inheritance is a term used for something else entirely.

What you're talking about is dynamic dispatch