Weird clang++ slowness

I found certain source files which are taking a lot of time to compile.
Upon investigation I measured this times:

9.8 seconds for command: clang++ -c -std=c++11 file.cpp

0.2 seconds for command: clang++ -E -std=c++11 file.cpp > f.CC
    (creates a 2.9 MB file)

3.4 seconds for command: clang++ -c -std=c++11 f.CC

So explicitly preprocessing and then compiling takes less than half the
time of compiling the original file.

I guess this is due to macro expansion tracking for diagnostic purposes.
The C++ file contains some errors (it belongs to a test suite) although
I see no references to macros on the output of the compiler.

So how can I speed up the compilation? Can this be considered a bug?

I found certain source files which are taking a lot of time to compile.
Upon investigation I measured this times:

9.8 seconds for command: clang++ -c -std=c++11 file.cpp

0.2 seconds for command: clang++ -E -std=c++11 file.cpp > f.CC
   (creates a 2.9 MB file)

3.4 seconds for command: clang++ -c -std=c++11 f.CC

So explicitly preprocessing and then compiling takes less than half the
time of compiling the original file.

I guess this is due to macro expansion tracking for diagnostic purposes.
The C++ file contains some errors (it belongs to a test suite) although
I see no references to macros on the output of the compiler.

So how can I speed up the compilation? Can this be considered a bug?

Could be a bug or just macro tracking with very deep instantiations.
Impossible to say without a test case.

- Ben

Hello Ben,

Benjamin Kramer <benny.kra@gmail.com>
writes:

I found certain source files which are taking a lot of time to compile.
Upon investigation I measured this times:

9.8 seconds for command: clang++ -c -std=c++11 file.cpp

0.2 seconds for command: clang++ -E -std=c++11 file.cpp > f.CC
   (creates a 2.9 MB file)

3.4 seconds for command: clang++ -c -std=c++11 f.CC

So explicitly preprocessing and then compiling takes less than half the
time of compiling the original file.

I guess this is due to macro expansion tracking for diagnostic purposes.
The C++ file contains some errors (it belongs to a test suite) although
I see no references to macros on the output of the compiler.

So how can I speed up the compilation? Can this be considered a bug?

Could be a bug or just macro tracking with very deep instantiations.
Impossible to say without a test case.

I think I hit a huge pessimization on Clang's diagnostic machinery. See
this test case:

#include "boost/asio.hpp"

double mainf();

int mainf() {
  foo(sdafo_2, 0);
  return 0;
}

Some timings:

Time (seconds) Command
6.8 clang -c -std=c++11 test.cpp
4.8 clang -c test.cpp

    (after replacing `sdafo_2' with `x')
1.0 clang -c test.cpp

    (after replacing `sdafo_2' with `o_2')
2.8 clang -c test.cpp

Also please note how Clang quickly reports the first error about the
ilegal overload of `mainf' and then there is a long lapse of time until
it reports the error concerning `sdafo_2'.

Thanks for the analysis Oscar, please file the bug. I suspect typo correction is the culprit here.

Hello Chandler,

Chandler Carruth <chandlerc@google.com>
writes:

Thanks for the analysis Oscar, please file the bug.

Done at 17698 – Clang spell checker is slow

I suspect typo correction is the culprit here.

That was my guess too. It seems that there is no method for deactivating
the feature (-fno-diagnostics-fixit-info looked promising but it made no
difference.)

-fno-spell-checking

[going back to cfe-dev]

Richard Smith <richard@metafoo.co.uk> writes:

Richard Smith <richard@metafoo.co.uk> writes:

> -fno-spell-checking

Thanks! I can't believe I missed that option.

It's not a very obvious name, given that we always call this
typo-correction, not spell-checking.

Actually, I searched both "typo" and "spell", but on the wrong place:

http://clang.llvm.org/docs/UsersManual.html

I also looked at the `clang++ --help' output, but reading all options,
not with text search. It seems that the list is too long for my
attention span :slight_smile: