C++ Logo


Advanced search

Re: extremely long compile time with large number of string literals

From: Thiago Macieira <thiago_at_[hidden]>
Date: Thu, 09 Jul 2020 16:15:03 -0700
On Thursday, 9 July 2020 14:46:56 PDT Mandeep Sandhu wrote:
> > Moreover, there's also the problem that some features can be misused or
> > abused. Creating 50k std::string in the same function is probably a bad
> > idea, let alone in the same statement.
> This isn't in a function, but in a header. Its static inventory list,
> which needs to be frequently checked for item membership (hence a set)
> and for performance reasons we'd like to have it ready before use.

It's a function, whether you realised it or not. Creating a std::string and
populating a std::unordered_set require a function, so the compiler created
one for you.

> > The exception handling code that needs to be generated will be enormous.
> Do you mean the code to _generate_ exception from the constructor? I'm
> not sure I follow you here.

std::string can throw. For the Nth string that can throw, the compiler needs
to generate code to destroy all the N-1 strings that were created before that
point, then resume the exception unwinding. Experimenting with GCC shows me
that, fortunately, the compiler generates a loop if you're using
std::initializer_list, so this is likely not the reason you're experiencing
long build times.

Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel System Software Products

Received on 2020-07-09 18:18:22