~/talk

Optimizing Away C++ Virtual Functions May Be Pointless

Talkat CppCon 2023 · on Friday, 2023-10-06· at 09:00· Adams, 6700 North Gaylord Rockies Boulevard· [rust]
links:none on file
slides:none on file

Benchmarks show surprising, inconsistent numbers: 2% faster 42% faster 54% faster on one run and 78% slower 14% slower 35% slower 18% slower on another. Real use case: a preprocessing step that serializes different formats, measured with a virtual-base-class runtime dispatch and a template-expanded compile-time dispatch. Results vary by CPU (Intel vs AMD), compiler (GCC vs Clang), and cache effects; std::variant/std::visit often fares worst and can deoptimize to indirect calls. Conclusion: measure the actual code+hardware+flags, don’t assume virtuals are inherently slower.

AI-written summary · about

  1. 0:00Virtual function myths
  2. 1:10Inheritance and virtual functions
  3. 3:44Benchmarking virtual functions
  4. 5:51Misleading benchmarks
  5. 7:57Serialization benchmark
  6. 10:06Hardware and compiler impact
  7. 12:13Cache behavior analysis
  8. 17:32Performance variability
  9. 20:42Virtual function importance
  10. 23:38Design philosophy
  11. 26:57Q&A
~/search
type to search 6,249 conferences, 138,987 speakers and 185,172 talks
~/help
cmdctrl k
search every conference, speaker and series
/
focus the filter search
h
home
c
conferences
s
speakers
e
series
t
light / dark — the status bar button does the same
?
this help
esc
close this, then clear every filter — or just the search, while you are typing in it

Ignored while you are typing. Pages without a filter rail have no search to focus.