https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124396
Bug ID: 124396
Summary: Optimize compile times for internal uses of
std::string
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Keywords: missed-optimization
Severity: enhancement
Priority: P3
Component: libstdc++
Assignee: unassigned at gcc dot gnu.org
Reporter: redi at gcc dot gnu.org
Target Milestone: ---
Currently any part of the library that uses std::string includes all of
<string>, e.g. <bitset>, <stdexcept>, <locale>, <sstream>, <fstream>, <chrono>,
<format>, <print>, <meta>, <regex>, <stacktrace>, ...
(For some reason <random> includes <string>, which could probably just be
removed with no further changes!)
Most uses only need the class template itself, and maybe operator==, they don't
need UDLs, std::to_string, std::stoi, std::hash<std::string>, etc.
operator< and operator+ are probably somewhere in the middle, some things use
them and others don't.
We could move a lot of the non-member functions out of bits/basic_string.h into
other headers, either directly into <string> or into new headers such as
bits/string_conv.h, bits/string_io.h, etc.
Then we could change our other headers to include <bits/basic_string.h> instead
of <string>. This could be done now for <meta>, but should wait for stage 1 for
other headers. Currently they'd need to also include <bits/basic_string.tcc>
but maybe that should just be included at the bottom of <bits/basic_string.h>
since you always need both.