Re:Trying out C++20's modules with Clang and Make
by cwzwarich on Sunday October 15, 2023 @11:27AM
(#37890528)
The one way in which they are slower than headers is that they create longer dependency chains of translation units, whereas with headers you unlock more parallelism at the beginning of the build process, but much of it is duplicated work.
Re:Trying out C++20's modules with Clang and Make
by klipt on Sunday October 15, 2023 @12:31PM
(#37891132)
I assume templates can only be partly preprocessed (parsed?) but not fully pre compiled, since final code depends on the template types?
Re:Trying out C++20's modules with Clang and Make
by vblanco on Sunday October 15, 2023 @12:50PM
(#37891319)
Yes, but template code is all on headers, so it gets parsed every single time its included on some compile unit. With modules this only happens once so its a huge speed upgrade in pretty much all cases.
Re:Trying out C++20's modules with Clang and Make
by moregrist on Sunday October 15, 2023 @01:07PM
(#37891480)
Whenever I’ve profiled compile times, parsing accounts for relatively little of the time, while the vast majority of the time is spent in the optimizer.
So at least for my projects it’s a modest (maybe 10-20%) speed up, not the order of magnitude speed up I was hoping for.
Thus C++ compile times will remain abysmal.
Re:Trying out C++20's modules with Clang and Make
by dagmx on Sunday October 15, 2023 @01:59PM
(#37891880)
For some template heavy code bases I’ve been in, going to PCH has cut my compile times to less than half. I assume modules will have a similar benefit in those particular repositories, but obviously YMMV
Re:Trying out C++20's modules with Clang and Make
by jcelerier on Sunday October 15, 2023 @02:02PM
(#37891895)
Depends on the compiler, clang is able to pre-instantiate templates and generate debug info as part of its pch system - (for instance most likely you have some std::vector<int> which can be instantiated somewhere in a transitively included header).
In my projects enabling the relevant flags gave pretty nice speedups.
Re:Trying out C++20's modules with Clang and Make
by maccard on Sunday October 15, 2023 @03:06PM
(#37892446)
Every post or exploration of modules (including this one) has found that modules are slower to compile.
> I expect the second you can reliably use that almost everyone will switch overnight just from how fast of a speed boost it gives on the STL vs even precompiled headers.
I look forward to that day, but it feels like we're a while off it yet
Downside is that at the moment you cant mix normal header STL with module STL in the same project (msvc), so its for cleanroom small projects only. I expect the second you can reliably use that almost everyone will switch overnight just from how fast of a speed boost it gives on the STL vs even precompiled headers.