Link-Time Optimization of Dynamic Casts in C++ Programs
summary
Link-time pass turns library dynamic_cast calls into short instruction sequences by laying out classes in preorder layout bounds checks, replacing linear DFS cast work with constant-time lower/upper bound comparisons, and drops unused RTTI by pruning RTTI vtable slots via liveness analysis. Prototype is an LLVM LTO pass evaluated on a ~50M‑LOC benchmark suite: average runtime improves ~1.4% and binaries shrink ~1.7%, with up to ~5% speedup (Solidity) and >4% size cut (Envoy). Replacing LLVM’s custom RTTI showed a 350% slowdown that the pass reduces to ~5%.
AI-written summary · about
chapters (10)
- 0:00Dynamic casts and RTTI overhead
- 3:55RTTI and dynamic casts problems
- 6:29Traditional optimization limits
- 7:58Link-time optimization for dynamic casts
- 10:49Evaluation setup and benchmarks
- 12:38Case study: LLVM dynamic casts
- 14:24Key takeaways and zero-overhead
- 15:27Q&A: Shared libraries
- 16:53Q&A: Cast distance
- 19:23Q&A: LTO compile-time cost
related talks
13mIs there life without RTTI or how to write your own dynamic_cast
05mGeneralised Double Dispatch
01h 33mDe-fragmenting C++: Making Exceptions and RTTI More Affordable and Usable
57mA Tour of Polymorphism Techniques in C++
50mC++ Costless Abstractions: the compiler view
10mStay in tune with your build using Build Insights
01h 44mImproving C++ Compilation Times: Tools & Techniques
49mAn Engineering Approach to Optimising C++
