Embracing (and also Destroying) Variant Types Safely
summary
Claims concrete tradeoffs: variant layout uses alignas plus a raw storage buffer and an active index, and destruction dominates performance so a poor destructor costs real money — an experiment cites a 0.5% homepage slowdown at scale. Three destruction strategies appear: linear runtime chain, mixed compile/runtime binary search (quadratic instantiations risk CI OOM), and an index-to-function table (constant time but optimization barriers). Also covers template deduction rules (greedy matching, fair matching) and argues for a type_sequence proposal to simplify metaprogramming.
AI-written summary · about
chapters (23)
- 0:00Intro
- 0:36Remote Work
- 3:05Slave
- 4:11Sponsorship
- 4:28Agenda
- 5:27Variatics
- 8:44Verdicts
- 11:28Verdicts are difficult
- 13:31Kinds
- 19:26Type Sequence
- 29:08Fair Matching
- 36:18Variants Everywhere
- 43:16Implementation
- 44:14Variant Alternative
- 46:45Linear Search
- 48:19Binary Search
- 48:56Runtime Binary Search
- 50:13Constant Given Index
- 50:51Constant Given Time
- 52:28Algorithm Selection
- 54:38Mixed Mode
- 56:38New Era
- 57:16Questions
related talks
01h 01mUsing Modern C++ to Eliminate Virtual Functions
01h 03mType Erasure - The Implementation Details
25mType System Tips for the Real World
56mC++ Relocation - How to Achieve Blazing Fast Save and Restore and More!
01h 01mBreaking Dependencies - C++ Type Erasure - The Implementation Details
36mThe language that isn't
48mBack to Basics: Cpp Value Semantics
59mstd variant and the power of pattern matching
