stdc++ issue: extremely long compile time with large number of string literals

Mandeep Sandhu mandeepsandhu.chd@gmail.com
Thu Jul 9 05:12:41 GMT 2020


Hi All,

I'm not sure if this is the right mailing list for asking about
(possible) g++ issues. If not, I'd appreciate it if someone can point
me to the right one.

With that said, here goes...

I have an strange (to me) issue, where trying to compile a header
which has a single "std::unordered_set<std::string>" initialized with
around 50K short strings is taking forever.

The set is declared as:
const std::unordered_set<std::string> my_set ({"item1", "item2", ....});

(The header is auto-generated using a script which takes a JSON array
and puts its elements in an unordered_set)

I understand that creation of many strings has an overhead, but this
issue seems to
affect compilation time, not runtime.

Can someone explain to me why it takes such a long time to compile?
Keeping the strings to under 5K, makes the program compile in about 8
secs.

I'm using the following compiler on Linux:
$ g++ --version
g++ (Ubuntu 9.2.1-9ubuntu2) 9.2.1 20191008
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Thanks for your time.

-mandeep


More information about the Gcc-bugs mailing list