C++ Logo

std-discussion

Advanced search

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

From: Ville Voutilainen <ville.voutilainen_at_[hidden]>
Date: Thu, 9 Jul 2020 12:50:39 +0300
On Thu, 9 Jul 2020 at 04:40, Mandeep Sandhu via Std-Discussion
<std-discussion_at_[hidden]> wrote:
>
> 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.

Overload resolution. Try passing suffixed-string literals,

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

Received on 2020-07-09 04:54:06