Back to Basics: Virtual Dispatch and its Alternatives
summary
Compares virtual table indirect calls (pointer derefs then indirect call) against CRTP and std::variant with visitor, benchmarks on a 10,000×10,000 pixel image applying a per‑pixel filter on Debian with GCC and Clang, using C++Insights and QuickBench style timing. Finds CRTP gives the best runtime at -O2/-O3, virtual dispatch is measurably slower, and the variant/visitor path sometimes deoptimizes (compiler falls back to runtime dispatch after repeated calls—reported as a bug).
AI-written summary · about
chapters (16)
- 0:00Introduction and motivation
- 1:58What we will cover
- 4:25Performance optimization goals
- 6:37Dynamic binding and virtual tables
- 8:05Tools for benchmarking
- 13:24Overhead of virtual tables
- 15:33Non-virtual inheritance limits
- 17:21CRTP for compile-time polymorphism
- 22:30Visitor pattern basics
- 26:53Compile-time visitor alternatives
- 29:46Limitations of Concepts
- 30:30Benchmark setup
- 31:40Performance results analysis
- 34:35Trade-offs in design choices
- 35:46Future of compile-time polymorphism
- 36:38Q&A session
related talks
57mA Tour of Polymorphism Techniques in C++
55mHow to "OO" in C++
47mDesign Patterns - The Most Common Misconceptions (2 of N)
04mAvoiding Virtual Call in CRTP
01h 23mRethink Polymorphism in C++
29mEffective replacement of dynamic polymorphism with std::variant
22mEffective replacement of dynamic polymorphism with std::variant
41mHigh-Performance Message Dispatch in C++
