Re:The Performance Impact of C++'s `final` Keyword
by Slix on Tuesday April 23, 2024 @04:44AM
(#40129839)
This optimization option isn't on by default? That sounds like a lot of missed optimization. Most programs aren't going to be loading from shared libraries.
Maybe I can set this option at work. Though it's scary because I'd have to be certain.
Re:The Performance Impact of C++'s `final` Keyword
by Thiez on Tuesday April 23, 2024 @08:17AM
(#40131052)
The JVM can actually perform this optimization optimistically and can undo it if the assumption is violated at runtime. So Java's 'everything is virtual by default' approach doesn't hurt. Of course relying an a sufficiently smart JIT comes with its own trade-offs.
Re:The Performance Impact of C++'s `final` Keyword
by soooosn on Tuesday April 23, 2024 @06:56AM
(#40130440)
I think you have answered your own question: If turning on the setting is scary for you in a very localized project at your company, imagine how scary it would be to turn on by default for everybody :-P
Re:The Performance Impact of C++'s `final` Keyword
by JonChesterfield on Tuesday April 23, 2024 @07:17PM
(#40138495)
Optimization means "make it faster without changing behaviour in ways I don't like". Clang can't generally default that one to on because it doesn't know whether you're going to splice in more code it can't see at runtime.
Lots of code gets slower if it might need to be called from something not currently in the compiler's scope. That's essentially what ABI overhead is. If there isn't already, there should be a compiler flag that says "this is the whole program, have at it" which implies the vtables option.
You can tell it "I won't do that" though with additional flags, like Clang's -fwhole-program-vtables, and even then it's not that simple. There was an effort in Clang to better support whole program devirtualization, but I haven't been following what kind of progress has been made: https://groups.google.com/g/llvm-dev/c/6LfIiAo9g68?pli=1