Live data from Hacker News

Optimizing the unoptimizable: a journey to faster C++ compile times

vitaut.net

1–10 of 32 posts

Re: Optimizing the unoptimizable: a journey to faster C++ compile times

#9
post #5

The real solution to fast compilation is to have modules. These kind of one-off hacks are interesting but will not scale.

> The real solution to fast compilation is to have modules.

I don't agree. The real solution for fast compilation times is to not have to recompile things. This means onboarding tools like ccache, organize your project around independent subprojects which eliminate/minimize compile-time dependencies, and leverage incremental builds.

There's a C++ book somewhere that describes how the subprojects approach helps lower build times to a residual length which if my memory doesn't fail me was dubbed horizontal architecture. It consists of designing every single subprojects to be stand-alone and leave any integration to the linking stage. I've used it in the past on a legacy C++ project that took slightly over 1h to pull off an end-to-end build, and peeling out 4 or 5 subprojects following the horizontal architecture approach allowed me to cut down full end-to-end build times to slightly over 8 minutes and incremental builds down to less than a minute, without bothering with compiler caches. I'm sure that if I bothered onboarding ccache I could drive incremental build times to just a few seconds.

If you know what you are doing, you can do a lot without begging for magic.

Re: Optimizing the unoptimizable: a journey to faster C++ compile times

#10

So why on earth is std::string so slow to compile, if it's possible to compile this full-featured formatting library in 1/4 of the time?

It isn't when using modules, import std brings in the whole standard C++ faster than that #include.

EDIT:

This compiles in 1 second on an i7 laptop.

    import std;

    int main()
    {
        std::cout 
Post reply on HN