The hidden compile-time cost of C++26 reflection

Reflection isn’t the slowdown — the giant header is, say devs

TLDR: Benchmarks show C++26 reflection itself is light, but including its big helper header can add hundreds of milliseconds per file, with heavier examples hitting seconds. Commenters split between blaming bloated standard library code and betting on modules or precompiled headers, agreeing that build speed is crucial for productivity.

C++ folks ran to test shiny new reflection, and the surprise twist is… the magic isn’t the problem. The author’s benchmarks on GCC 16 show flipping on reflection itself adds basically nothing, while pulling in the big new <meta> header slams builds with ~310 ms per file. One flashy example spiked to 1.6 seconds, though precompiled headers trimmed it to ~1.27 seconds. Translation: the language feature feels light; the standard library plumbing feels like the heavy suitcase. And if your app has many files, expect that overhead multiplied.

Cue the comment fireworks. jstimpfle rolls eyes with “hidden cost of almost any C++ feature,” turning the post into a meme about C++ bloat. leni536 calls out <print> as a heavyweight villain and swears fmtlib compiles faster, while wjakob drops the nihilist take: feature creep is out of control and “modules won’t save us.” Meanwhile, SuperV1234 is in the lab trying “import std” modules to see if it helps, and dalvrosa just found a new benchmarking toy in hyperfine. The vibe? Team “STL is the bottleneck” vs Team “use modules/PCH and chill.”

Between jokes about “boomer loops” and “kitchen-sink headers,” the crowd agrees on one thing: fast builds = happy devs. The real drama isn’t the reflection mirror — it’s everything dragged in behind it.

Key Points

  • GCC 16 experimental support for C++26 reflection was benchmarked using hyperfine on Debian 13 Slim in Docker.
  • Enabling -freflection showed no measurable overhead for an empty main (43.1 ms observed baseline).
  • Including the <meta> header added ~310.4 ms; a basic struct reflection compiled in 331.2 ms, implying most cost from <meta>.
  • Scaling reflection from 1 to 20 unique struct types increased compile time from 331.2 ms to 410.9 ms.
  • A complex AoS→SoA example compiled in 1,622.0 ms; using PCHs for <meta>, <ranges>, and <print> reduced this to 1,265.0 ms.

Hottest takes

"The hidden compile-time cost of <insert almost any C++ feature>" — jstimpfle
"libstdc++'s <print> is very heavy, reflection or not" — leni536
"The mantra 'It's okay, modules will save us' is naive" — wjakob
Made with <3 by @siedrix and @shesho from CDMX. Powered by Forge&Hive.