On Thu, 9 Jul 2020, Mandeep Sandhu via Gcc-help wrote:
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.
You didn't say what flags you are using. For anything autogenerated like that, going above -O1 is always risky.
One first thing to try is -ftime-report At -O0 phase opt and generate : 3.46 ( 84%) 0.15 ( 45%) 3.62 ( 81%) 188385 kB ( 70%) without a specific pass that stands out. At -O1 phase opt and generate : 87.96 ( 99%) 6.57 ( 97%) 94.56 ( 99%)24503776 kB (100%) callgraph ipa passes : 85.93 ( 97%) 6.52 ( 96%) 92.47 ( 97%)24413253 kB ( 99%) tree eh : 84.32 ( 95%) 6.43 ( 95%) 90.78 ( 95%)24340697 kB ( 99%) so, it looks related to the optimization of exceptions... -- Marc Glisse