top | item 39249824

(no title)

hielke | 2 years ago

In modern C++ there will be modules (C++20). Even std will be available as a module (C++23). This will likely bring down compile times massively. But so far the only compiler with support for this today is MSVC.

discuss

order

JonChesterfield|2 years ago

Did someone get around the modules-linearise-the-build-graph problem?

In the before times, people were enraged with C++ compile times and wanted a solution. Modules could have fixed that, thus people assumed modules would fix that.

Then modules were designed with the primary motive of removing preprocessor macros from the language, with reference to fortran's binary module description model. The one that turns the trivially parallel compilation model into a directed graph.

I'm under the impression that C++ modules as shipped require you to build dependencies before uses and the inevitable linearisation of the build graph is considered "probably fine, whatever". Compiling individual translation units gets somewhat faster as you don't need to parse the headers each time, but you can no longer build everything simultaneously.

Do modules actually make compilation appreciably faster in msvc?

delta_p_delta_x|2 years ago

> modules-linearise-the-build-graph problem

Modules don't linearise the build graph. Any independent modules are compiled in parallel, but dependents will wait for these modules to be compiled.

In fact the problem is the other way round: header-translation unit compilation does a ton of unnecessary repetitive copy-pasting and parsing in the name of achieving embarrassingly parallel compilation. IMO modules help express build and API dependencies clearer, and even despite the so-called loss of parallelisation, build times with modules are generally an order of magnitude faster.

An extreme example is Vulkan-Hpp, which has a module interface file[1], and header files that exceed 150K lines of code, cumulatively. Using these headers means even a simple example takes something like 20+ seconds to compile every time. This is even worse when using complicated standard headers like `<algorithm>`, `<functional>`, `<ranges>`, etc.

On the other hand, using the module, the compile only takes as long the first time, and every subsequent compile is lightning-quick.

[1]: https://github.com/KhronosGroup/Vulkan-Hpp/blob/main/vulkan/...

hielke|2 years ago

>Do modules actually make compilation appreciably faster in msvc?

For a small toy example, about 10x times faster. Don't know how that looks in real life projects.

synergy20|2 years ago

are you saying with c++ module parallel make is nearly impossible?

NekkoDroid|2 years ago

> Even std will be available as a module (C++23)

All 3 major compilers offer the std module in C++20 as an extension, at least I remember an issue where it was discussed and agreed uppon by all. I don't actually know if it was actually implemented (yet?).