libcxx performance issue

Dear developers,

Sorry to bother you, but I’ve met a wired problem using clang with libcxx.

I’ve built clang and libcxx with clang, and trying to compile c++ program with libc++, but compilation is extremely slow when using libcxx, as below:

$ time clang++ -o /dev/null -std=c++11 -stdlib=libc++

clang++ -o /dev/null -std=c++11 -stdlib=libc++ 4.29s user 0.06s system 97% cpu 4.476 total

$ time clang++ -o /dev/null -std=c++11

clang++ -o /dev/null -std=c++11 1.41s user 0.06s system 92% cpu 1.582 total

I wonder if you have any idea where should I start to address this issue, or anything I probably configured wrong? Thanks in advanced.



You would need to tell us what you’re actually compiling before we can guess at the problem.


Sorry for missing that, it’s one (randomly selected) STL #include with an empty main function as below:
$ perf stat -a – clang++ -o /dev/null --compile -std=c++11

Performance counter stats for ‘system wide’:

6286.898000 cpu-clock (msec) # 7.984 CPUs utilized
1,029 context-switches # 0.164 K/sec
23 cpu-migrations # 0.004 K/sec
5,069 page-faults # 0.806 K/sec
3,359,820,123 cycles # 0.534 GHz
3,011,112,580 instructions # 0.90 insn per cycle
565,470,025 branches # 89.944 M/sec
3,667,572 branch-misses # 0.65% of all branches

0.787455804 seconds time elapsed

$ perf stat -a – clang++ -o /dev/null --compile -std=c++11 -stdlib=libc++

Performance counter stats for ‘system wide’:

20095.100787 cpu-clock (msec) # 7.995 CPUs utilized
1,128 context-switches # 0.056 K/sec
44 cpu-migrations # 0.002 K/sec
7,716 page-faults # 0.384 K/sec
11,861,997,273 cycles # 0.590 GHz
10,930,520,024 instructions # 0.92 insn per cycle
2,064,359,090 branches # 102.729 M/sec
10,959,608 branch-misses # 0.53% of all branches

2.513417717 seconds time elapsed

$ clang++ -o libstdcxx.o -std=c++11
$ clang++ -o libcxx.o -std=c++11 -stdlib=libc++

$ ldd libstdcxx.o (0x00007fff3efc7000) => /home/yiyan/.local/lib64/ (0x00007fb320d6f000) => /lib/x86_64-linux-gnu/ (0x00007fb3209d1000) => /home/yiyan/.local/lib64/ (0x00007fb3207b9000) => /lib/x86_64-linux-gnu/ (0x00007fb3203c8000)
/lib64/ (0x00007fb32114e000)

$ ldd libcxx.o (0x00007fffd8fe4000) => /home/yiyan/.local/lib/ (0x00007f01bbcba000) => /home/yiyan/.local/lib/ (0x00007f01bba65000) => /lib/x86_64-linux-gnu/ (0x00007f01bb6c7000) => /home/yiyan/.local/lib64/ (0x00007f01bb4af000) => /lib/x86_64-linux-gnu/ (0x00007f01bb0be000) => /lib/x86_64-linux-gnu/ (0x00007f01bae9f000) => /lib/x86_64-linux-gnu/ (0x00007f01bac97000)
/lib64/ (0x00007f01bbfc8000)

$ cat

int main() {}


I’m afraid I have no idea what you’re comparing with.

If you have an old libstdc++ (say), then that will be much faster, because it’s missing lots of C++11 features.
But that’s just a guess.

– Marshall

Or rather, comparing against.
What are you using when you’re not using libc++?

– Marshall

I’m using trunk version of both libstdc++ and libc++.