Avoiding Virtual Call in CRTP
summary
Embedded serialization needs extremely low overhead so a virtual call is unacceptable. A CRTP-based base class replaces repeated implementations and an initial design with a virtual method shows a vcall in Visual Studio assembly. Replacing the virtual call by casting this to the derived type inside the base and invoking a static member lets the compiler resolve the call at compile time so the call becomes inlined by MSVC, yielding CRTP without runtime dispatch and meeting the performance constraint.
AI-written summary · about
chapters (5)
related talks
05mGeneralised Double Dispatch
40mBack to Basics: Virtual Dispatch and its Alternatives
57mA Tour of Polymorphism Techniques in C++
13mIs there life without RTTI or how to write your own dynamic_cast
58mRust Traits In C++
01h 26mC++ Under the Hood: (Internal Class Mechanisms)
15mC++ devirtualization in clang
01h 33mDe-fragmenting C++: Making Exceptions and RTTI More Affordable and Usable
