C++ Logo

std-discussion

Advanced search

extremely long compile time with large number of string literals

From: Mandeep Sandhu <mandeepsandhu.chd_at_[hidden]>
Date: Wed, 8 Jul 2020 18:39:35 -0700
Hi All,

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 (its been more than 20 mins
since I started).

The set is declared as:

const std::unordered_set<std::string> my_set ({"item1", "item2", ....});

I understand that creation of many strings has an overhead, but this
during compilation, 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

Received on 2020-07-08 20:43:01