std::visit is required by the C++ standard to run in O(1) time, which forces implementations to use a function pointer jump table. This prevents the compiler from inlining trivial visitors, hurting performance in hot paths. The author implements an alternative visit using compile-time if-else recursion over all index combinations, allowing the compiler to inline visitor calls. Benchmarks on a vector of 5000 elements show the inlining-friendly version is significantly faster for simple visitors, especially with small numbers of variant types. The standard library's O(1) implementation also turns out not to be strictly O(1) in practice.
Sort: