https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125329
Bug ID: 125329
Summary: Compilation performance of C++ reflection slower with
`import std;` than with header inclusion
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: boris at kolpackov dot net
Target Milestone: ---
I ran a benchmark on GCC 16.1.0 (from Debian, compiled with
--enable-checking=release) and found that code that uses C++26 reflection
compiles slower with `import std;` than with including `<meta>` as a header.
The benchmark compiles (in parallel) 128 translation units each of which
includes `<meta>`, imports `std`, or imports `<meta>` and converts a C++ enum
to string using reflection. Note that compilation of the `std` module or
`<meta>` header unit is excluded from the measurement. In other words, this
tries to measure the compilation speed in a realistic development setup.
Here are the numbers for GCC 16.1.0 (the absolute values are not important but
they were obtained on i9-12900K):
include-hdr import-std import-hdr
--------------------------------------------
GCC 16 3.11s 3.44s 1.65s
The benchmark (with instructions) is available here:
https://github.com/boris-kolpackov/libenum-to-string-bench
See also bug #125328.