C++ Logo

STD-DISCUSSION

Advanced search

Subject: Re: extremely long compile time with large number of string literals
From: Ville Voutilainen (ville.voutilainen_at_[hidden])
Date: 2020-07-09 04:50:39


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, ....});


STD-DISCUSSION list run by std-discussion-owner@lists.isocpp.org

Older Archives on Google Groups