[cfe-dev] Can we make libcxx headers more modular for faster compilation?

Yaron Keren yaron.keren at gmail.com
Wed Oct 2 09:27:09 PDT 2013


Hi Chandler,

First let me say your GoingNative 2013 talk was very interesting. There is
lots of potential in improving the efficiency and reliability of C++
programming, especially with the new feature in C++ 11. One has to
de-program old habits to use these features.

To the subject, I did not meaure times exactly since the effect was very
noticable for a trivial test program, three times as slow!

Here are the combinations I tested:

clang + libcxx iostream = about 3 seconds
clang + libstdc++ iostream = about 1 second
clang + libc stdio.h = about 1 second

gcc + libcxx iostream = about 3 seconds
gcc + libstdc++ iostream = about 1 second
gcc + libc stdio.h = about 1 second

clang.exe is from http://llvm.org/builds/, gcc is MingW-builds 4.8.1 32 bit.

For clang + libcxx the command was:

clang main.cpp -nostdinc -I../libcxx -I../mingw-4.8.1 -target
i686-pc-mingw32 -Wno-deprecated-register -Wno-ignored-attributes
libc++.dll.a libc++abi.dll.a -o main.exe

For clang + libstdc++ the command was:

clang main.cpp -nostdinc -I../libstdc -I../libstdc/i686-w64-mingw32
-I../mingw-4.8.1 -target i686-pc-mingw32 -Wno-deprecated-register
-Wno-ignored-attributes libstdc++.dll.a -o main.exe

For gcc + libstdc++ the command was:

gcc main.cpp -lstdc++

For gcc + libcxx the command was:

gcc main.cpp -std=c++11 -nostdinc -I../libcxx -I../libstdc/i686-w64-mingw32
-I../mingw-4.8.1  -lstdc++  libc++.dll.a libc++abi.dll.a

These results were repeatable when running mutiple times.

The iostream code is:

#include <iostream>

int main() {
  std::cout<<"hello cout\n";
  return 0;
}

The stdio.h code is:

#include <stdio.h>

int main() {
  printf("hello printf\n");
  return 0;
}

The headers used with gcc are the defaults.
The headers used for clang are libcxx or libstdc++ for C++ and MingW 4.8.1
for the C library.

So when compiling small modules, libcxx slows down compilation considerably
compared with including libstdc++.

Yaron





2013/10/2 Chandler Carruth <chandlerc at google.com>

> On Wed, Oct 2, 2013 at 6:16 AM, Yaron Keren <yaron.keren at gmail.com> wrote:
>
>> For example, including iostream also includes:
>>
>> iostream:38:
>> ios:216:
>> __locale:15:
>> string:439:
>> algorithm:627:
>> memory:603:
>> tuple
>>
>> That's tons of baggage which slows down compilation significantly.
>>
>
> Have you measured it? Especially for non-trivial translation units? I have
> tried, and been unable to measure significant (> 5%) changes by minimizing
> standard library includes.
>
> Also, we're working on C++ modules which will largely eliminate *any* cost
> associated with "bundling" together N different headers as part of a
> library.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20131002/4376bc24/attachment.html>


More information about the cfe-dev mailing list