Skip to content

Compiling attached file which uses boost::container::flat_set is very slow with clang & create large .text section #62202

@DominiquePelle-TomTom

Description

@DominiquePelle-TomTom

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

Attached preprocessed source file (with Boost 1.81):
brands-preproc.cpp.gz

Benchmarks with Clang 16 + Boost 1.81.0 (on 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

Metadata

Metadata

Assignees

Labels

clangClang issues not falling into any other categoryslow-compile

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions