3 ms·
> This is not true. Compile times are usually much better with modules. What significantly improves compile-times is Pre-Compiled Headers (PCH), which most com
by volta83 5y ago
> This is not true. Compile times are usually much better with modules.
What significantly improves compile-times is Pre-Compiled Headers (PCH), which most compilers have supported for decades.
The study you mention, does not show data for them.
Having ported one >1 million LOC C++ app to use modules in two compilers, the compile time improvement of modules over PCH was not distinguishable from noise.
Modules have many advantages, like better encapsulation, etc.
The main thing people want from them seems to be better compile times, which is the one thing they don't deliver, at least over the PCH solutions that have existed for decades, are already supported by all build systems, etc.
Compared to modules, PCHs are "zero-effort" and deliver performance instantaneously.
- colomon 5y agoOff-topic, but is there a guide to best practices for portable pre-compiled headers out there somewhere? I'm under considerable pressure to add pre-compiled headers for Windows to my code, and it won't have any significant benefit for me unless I can also make it work on MacOS and Linux. So far my Googling has turned up little information for any platform other than Windows, and nothing that would suggest how to do it well for all three platforms. (Well, more to the point, Visual C++, clang, and g++.)
- volta83 5y agoDoes your project use CMake ? CMake supports these with all major compilers... I'll just google "<your build system> pre-compiled headers" and see if there is a flag or option that you can enabled. You will definetly need quite a bit of fine tuning for apps over 500k LOC or so, but if your app is under that, and you are splitting code between .h and .cpp files appropriately, just flipping a flag might get you 80% there. The speed ups you see people get from PCHs is like 20-30% faster compile-times. So they are more a "nice to have" feature than something that will solve your compile-time problems. If your app is structured in such a way that it takes 20 min to compile, this can cut it to 15 min at most, but that would probably still suck. If you want more, then you'd need to consider other solutions like distributed build caches (sccache, etc.).
- jcelerier 5y agoWith cmake it's just target_precompile_headers: https://cmake.org/cmake/help/latest/command/target_precompile_headers.html https://cmake.org/cmake/help/latest/command/target_precompil...