The hidden compile-time cost of C++26 reflection
4 days ago
- #C++26
- #Compilation
- #Reflection
- C++26 reflection is a powerful feature, but its compile-time impact is a concern.
- Fast compilation times are crucial for productivity and motivation in C++ development.
- The Standard Library, not language features like templates, is the main bottleneck for compilation speed.
- Using minimal Standard Library can drastically reduce compilation times, as shown by a fork of SFML compiling in ~4.3s.
- Reflection in C++26 is not purely a lightweight language feature, impacting compile times.
- Benchmarking GCC 16 with reflection shows varying compile times based on usage scenarios.
- Including `<meta>` adds ~310 ms, while `<ranges>` and `<print>` add significant overhead.
- Precompiled headers (PCH) are essential for scaling reflection usage, reducing compile times significantly.
- Modules show potential but currently do not outperform PCH in reducing compile times.
- Reflection will likely lead to widespread use of `<meta>` and other dependencies, increasing compile overhead.
- The author advocates for minimizing Standard Library dependencies to improve compilation speed and productivity.