C++ Run-Time Optimizations for Compile-Time Reflection
summary
C++26 static reflection plus C++20 tricks get applied to enum_to_string and string_to_enum, with concrete code paths and benchmarks. LLVM MCA guides decisions between if/else, nested switch/jump tables, SIMD vector compares and a BMI2 pext bit extract based lookup that builds a compile‑time mask and a perfect (or minimal perfect) hash table via constexpr search. Results show constant‑time register lookups and an order‑of‑magnitude speedup over naive approaches for typical enums, at the cost of heavier compile‑time work and hardware fallbacks.
AI-written summary · about
chapters (13)
- 0:00C++ compile-time reflection intro
- 3:18Why compile-time reflection excites
- 7:14Reflection in C++26 operators
- 12:36Performance analysis with analyzer
- 16:51Enum to string with reflection
- 21:51SIMD vectorization for enum conversion
- 27:59Switch case generation acceleration
- 35:02Perfect hashing for enum to string
- 43:30x86 hardware-accelerated hashing
- 48:35Benchmarking enum conversion methods
- 53:00Enum conversion with compile-time hashing
- 56:52Minimal perfect hashing for strings
- 1:03:42Summary of reflection trade-offs
related talks
01h 08mReflections: Compile-time Introspection of Source Code
01h 09m“Compile-time programming and reflection in C++20 and beyond”
01h 27mC++ Reflection - Back on Track
55mC++14 Reflections Without Macros, Markup nor External Tooling..
01h 11mKeynote: C++ Horizons
01h 01mReflection
36mCompile-time reflection, Serialization and ORM
01h 10mReflection Is Good for C++ Code Health
