A Tour of Polymorphism Techniques in C++
summary
Compares concrete C++ techniques: measured a simple draw loop with virtual functions costing about 88 ms per iteration versus a CRTP compile‑time approach around 5 ms, and a variant-based visitor that runs ~266 ms on GCC 11 but becomes much faster on GCC 12; uses Compiler Explorer to inspect generated code and shows that implementations (vtable vs optimized variant code) drive the overhead; covers CRTP, modern concepts as a clearer compile-time interface, and practical build-time choices.
AI-written summary · about
chapters (8)
- 0:00Introduction to polymorphism
- 1:44Polymorphism and overhead
- 5:31Virtual function performance
- 14:24Alternative implementations
- 21:00Virtual function analysis
- 30:05Compile-time interfaces
- 39:10Using std::variant
- 49:20Conclusion and best practices
related talks
55mHow to "OO" in C++
40mBack to Basics: Virtual Dispatch and its Alternatives
01h 23mRethink Polymorphism in C++
05mGeneralised Double Dispatch
58mBetter Code: Runtime Polymorphism
01h 25mComparing 'Classic C++' and 'Modern C++' Ways to Solve Programming Tasks
50mC++ Costless Abstractions: the compiler view
05mPostmodern Meta C++
