The Performance Impact of C++'s `final` Keyword

# · 🔥 245 · 💬 264 · 11 days ago · 16bpp.net · hasheddan · 📷
I would never do this in an actual product, but it provides us a really nice way to apply the final keyword to the code and turn it on and off as we need it for the experiment. The script reported using final slightly faster; wtih final it took 11m 29s. Without final it was 11m 44s. That's +2%. Actually significant. Each scene is different, and contains a different amount of objects that are marked with final. If we're hitting it for 50%+ of our test cases it seems like using final is something that we should consider. More than 90% of test cases ran at least 5% slower with final turned on!! Remember how I said a 1% increase is good for some applications? A 1% hit is also bad. Windows with MSVC isn't faring too well either. Just switching the compiler over to Clang there's a major perf hit of -5% and -17% on those same two scenes!! MSVC looks to be a bit of a mixed bag where some scenes are more performant with final and others ones take a significant hit. Whether there were many virtual objects had next to no correlation if final was a performance boon or hit.
The Performance Impact of C++'s `final` Keyword



Send Feedback | WebAssembly Version (beta)