Optimising Compiler Performance: A Case For Devirtualisation
May 21, 2024ndepalo

Summary
This post details the technical implementation of devirtualisation in C++ compilers. It explains the performance overhead of virtual functions due to vtable lookups and indirect calls, contrasting it with direct calls. The post discusses how compilers can devirtualise calls when the object type is known at compile time, highlighting the roles of `-fwhole-program` and `-flto` compiler flags, and the `final` keyword. A benchmark is presented to demonstrate the performance gains.