Benjamin Summerton, the author of the Ray trace system psraytraace, recently conducted a study on the impact of the C++ keyword “final” on application performance. The keyword “final” was introduced in the standard C++ 11, with claims suggesting it could improve performance. However, these claims lacked concrete evidence.
Benjamin’s testing revealed that the performance impact of using “final” varied significantly depending on the compiler. While GCC showed an increase in performance in some cases, Clang and MSVC saw a decrease in performance in most cases, and to a greater extent. Additionally, the performance impact was also influenced by the platform, with AMD Ryzen 9 6900HX system showing more noticeable changes compared to the system with Apple M1 CPU.
For instance, on the AMD Ryzen 9 6900HX Ubuntu 23.10 system, when compiled with Clang, there was a slowdown of at least 5% in 90% of the tests when using “final”, while in 2.5% of cases, there was an acceleration of at least 5%. Comparatively, using GCC resulted in a 5% slowdown in 0.9% of cases and a 5% acceleration in 15.8% of cases. Based on his findings, Benjamin concluded that avoiding the use of “final” would be advisable.