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++ test.cc

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

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

clang++ -o /dev/null -std=c++11 test.cc 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.

Best,

Yichen

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

/Eric

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 test.cc

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++ test.cc

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 test.cc
$ clang++ -o libcxx.o -std=c++11 -stdlib=libc++ test.cc

$ ldd libstdcxx.o
linux-vdso.so.1 (0x00007fff3efc7000)
libstdc++.so.6 => /home/yiyan/.local/lib64/libstdc++.so.6 (0x00007fb320d6f000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fb3209d1000)
libgcc_s.so.1 => /home/yiyan/.local/lib64/libgcc_s.so.1 (0x00007fb3207b9000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fb3203c8000)
/lib64/ld-linux-x86-64.so.2 (0x00007fb32114e000)

$ ldd libcxx.o
linux-vdso.so.1 (0x00007fffd8fe4000)
libc++.so.1 => /home/yiyan/.local/lib/libc++.so.1 (0x00007f01bbcba000)
libc++abi.so.1 => /home/yiyan/.local/lib/libc++abi.so.1 (0x00007f01bba65000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f01bb6c7000)
libgcc_s.so.1 => /home/yiyan/.local/lib64/libgcc_s.so.1 (0x00007f01bb4af000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f01bb0be000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f01bae9f000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f01bac97000)
/lib64/ld-linux-x86-64.so.2 (0x00007f01bbfc8000)

$ cat test.cc
#include

int main() {}

Yichen

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++.