<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/62202>62202</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Compiling attached file which uses boost::container::flat_set is very slow with clang & create large .text section
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          DominiquePelle-TomTom
      </td>
    </tr>
</table>

<pre>
    Compiling the attached file "brands.cpp" file (or its preprocessed
file "brands-preproc.cpp") which uses boost::container::flat_set is
very slow with clang (any version) when using boost-1.81.0.
It was much faster with boost-1.80.0 somehow and is much faster
with any version of gcc.

Furthermore, the size of the .text section is much bigger
when using boost-1.81.0 than with boost-1.80.0 and when
using clang (any version). The .text section is also much smaller
with any version of gcc.

The source file "brands.cpp" is a simplification of an actual file in my
project. Note that the code is in anonymous namespace (removing the
anonymous namespace makes the compilation time much faster,
presumably because there are more optimizations in the
anonymous namespace).

Attached file: brands.cpp.gz
[brands.cpp.gz](https://github.com/llvm/llvm-project/files/11259089/brands.cpp.gz)

Attached preprocessed source file (with boost-1.81):
[brands-preproc.cpp.gz](https://github.com/llvm/llvm-project/files/11259234/brands-preproc.cpp.gz)

Benchmarks with clang-16 + boost-1.81.0 (on Linux Ubuntu-22.04):
```
$ time clang++-16 -isystem boost-1.81 -O2 -std=c++14 -o brands.o -c brands.cpp

real    2m3.055s
user    2m2.411s
sys 0m0.632s

$ size brands.o
   text    data     bss     dec     hex filename
2635353   20032      48 2655433  2884c9 brands.o
```

Compare with gcc-12.1:
```
$ time gcc-12 -isystem boost-1.81 -O2 -std=c++14 -o brands.o -c brands.cpp

real 0m2.582s
user    0m2.476s
sys     0m0.105s

$ size brands.o
 text    data     bss     dec     hex filename
 182851   15088      48 197987   30563 brands.o
```

In other words:
* compilation is 47.6 times slower with clang-16 than with gcc-12.1
* .text section is 14.1 times bigger with clang-16 than with gcc-12.1

It's even worse with older clang compilers. The table below shows
the compilation time of attached "brands.cpp" file and size of the .text
section with various compilers using boost-1.80 and boost-1.81:

```
compiler   boost compilation time    size .text section
--------   -----   ---------------- ------------------
clang-16   1.81         125.582 sec       2,635,353 bytes
clang-16   1.80           2.164 sec         101,280 bytes

clang-15   1.81         137.508 sec       2,861,332 bytes
clang-15   1.80           2.527 sec         107,944 bytes

clang-14   1.81         153.504 sec       3,033,487 bytes
clang-14   1.80           2.294 sec         111,599 bytes

clang-5.0  1.81         276.031 sec       2,720,187 bytes
clang-5.0  1.80           2.328 sec         126,811 bytes

gcc-12.1   1.81           2.821 sec         139,833 bytes
gcc-12.1   1.80           2.505 sec         140,217 bytes

gcc-11.3   1.81           2.128 sec         182,038 bytes
gcc-11.3   1.80           2.121 sec         182,158 bytes

gcc-7.5    1.81           1.943 sec         121,497 bytes
gcc-7.5    1.80           1.707 sec         122,050 bytes
```

Full versions of compiler used in above table (--version option):

- `Ubuntu clang version 16.0.2 (++20230414073413+b5aa566a7e53-1~exp1~20230414073428.73)`
- `Ubuntu clang version 15.0.7`
- `Ubuntu clang version 14.0.0-1ubuntu1`
- `clang version 5.0.2 (tags/RELEASE_502/final)`
- `gcc-12 (Ubuntu 12.1.0-2ubuntu1~22.04) 12.1.0`
- `gcc-11 (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0`
- `gcc-7 (Ubuntu 7.5.0-6ubuntu2) 7.5.0`

I also reported this issue for boost since there is a large
compilation time & .text section regression from boost-1.80
to boost-1.81. See:
https://marc.info/?l=boost-users&m=168173836211082&w=2

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0WEuP47gR_jX0pSCCLIp6HHzoxzSwwCIJspPzgpLZtrKS6JBU9_Qc5rcHFCW3JLs3PUFiDFpjmvXVVw9WFaWca4691nsi74l83KnBn4zdP5qu6Zt_Dfpvum118tV0X023q8zhbf9gunPTNv0R_EmD8l7VJ32A56bVQBArq_q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