r/cpp • u/TheCrush0r • 10d ago
Compile-Time Improvements in LLVM 23
https://aengelke.net/llvm23-ct.html34
u/fortsnek274 10d ago
Did they try using modules? /s
33
u/TheCrush0r 10d ago
You might be joking, but the answer is yes. They ended up using precompiled headers instead: https://discourse.llvm.org/t/rfc-use-pre-compiled-headers-to-speed-up-llvm-build-by-1-5-2x/89345
13
u/fortsnek274 10d ago
And they have tried clang modules, which would be rather odd for a compiler of a language that has standard modules.
The poster says (clang?) modules "kill parallelism." I wonder what was modularised. Should probably only do it for what they're creating PCHs for. The std lib, core functions.
Make Clang 3x faster. I see no fundamental reason why parsing C++ has to be this slow, but this is very unlikely to happen (I’m not going to write a new C++ parser and I believe Clang still has the trend of becoming slower over time).
Rewrite LLVM in a language that compiles faster… haha, just kidding.
Yeah. What's needed, a template cache? Somebody at https://discourse.llvm.org/t/cache-template-instantiations-across-tus-proposal/86497 thought of that, but then decided it wasn't worth it.
They have DLL'ified the Windows build though, apparently. That would help if I ever need it.
4
u/jetilovag 9d ago
The explicit limitation of exported symbols to the public API is very much welcome and is what enables DLL builds on Windows. Release binaries can be much smaller and as a bonus also lights up plugin support on Windows. AdaptiveCpp can finally ship as a plugin, not a full-blown toolchain.
3
2
u/gracicot 8d ago
To be honest, switching to named modules in a codebase of that scale must be quite the undertaking
1
u/fortsnek274 8d ago
Not really, you only need to import ext libs, std, and core stuff for best build perf. It would be great if compilers could do it automatically, but MSVC only seems to be able to translate to header unit imports rather than named module imports. Or rather, you'd probably need to translate to a header that does the import and brings in macros.
2
u/pjmlp 10d ago
Actually it isn't that odd, the two former big contributors, were responsible for header modules, and at least in what concerns to Apple's own clang downstream, those are the ones that matter.
They are used for Objective-C and Objective-C++ modules, interop between Objective-C and Swift, and newly Swift and C++.
They are also used by the new build system improvements introduced about two years ago, explicit modules building.
Finally if you go to Apple's XCode support page for ISO C++, you will notice there aren't any rows for C++20 modules, nor import std, where one would expect to at least have them listed with no/XCode version instead.
And in what concerns Google, they are more busy with other languages to care about C++20 modules, while clang header maps do their job already.
6
u/sweetno 10d ago
I've heard PCHs interfere with ccache and friends. Is this ever a concern?
1
u/JustCopyingOthers 6d ago
I have experienced that. It is hard to get high ccache hit ratios in a CI environment that builds multiple versions though as different dependency versions invalidate prebuilt code that would otherwise be identical. So PCH does have a place.
2
u/_Noreturn 10d ago
Will unity builds come sometime
3
u/LongestNamesPossible 10d ago
What do you mean? Just make some fat compilation units yourself and get your number in the range of the cores on your computer.
7
0
u/VoidVinaCC 9d ago
Yeah its odd considering those would probably be the biggest improvement....
0
u/_Noreturn 9d ago
I mean it does make sense as llvm uses
using namespace clangin each source file instead of opening a namespace like others do to catch link errors quicker, but this costs the ability to do unity builds as it is basically like doing ausing namespacein a header file which could cause issues.also unity builds will also act like a kind of poor man lto that is faster to compile so it is a win
0
u/VoidVinaCC 9d ago
unity builds are free lto, faster builds, a lot less memory usage, a lot less disk and os stress.. at the cost of... having a cleaner codebase..? its ONLY wins!
1
u/ABlockInTheChain 8d ago
at the cost of... having a cleaner codebase..? its ONLY wins!
The cost is completely foregoing all TU-local constructs.
Personally I think that's fine because I never used TU-local anything before so there wasn't much to give up when I started experimenting with unity builds, but apparently some project lean on those very heavily.
1
u/VoidVinaCC 8d ago
Ive converted various (and big) codebases to unity-capable ones before, its not much of an issue tbh
1
u/_Noreturn 5d ago
This isn't even true, you can have TU local stuff with help of cmake UNITY_BUILD_UNIQUE_ID
cmake set_target_properties(myTarget PROPERTIES UNITY_BUILD "ON" UNITY_BUILD_UNIQUE_ID "UNIQUE" )then you can do this in your source files
```cpp namespace UNIQUE { static int x = 1; }
int func() { UNIQUE::x = 1; }
// another translation unit namespace UNIQUE { static int x = 1; }
int func2() { UNIQUE::x = 1; // different x. } ```
internally cmake does this
```cpp
define UNIQUE _19389493
include "cppfile1"
define UNIQUE _829283948
include "cppfile2"
```
0
u/_Noreturn 9d ago
only "loss" is slower incremental builds, which isn't even 100% true, since if you edit a header unity builds will be faster than normal builds. and if they open a namespace instead of doing a using namespace it should be possible and I think it could be automated ad well.
```cpp // they do this
using namespace clang;
void foo(SomeClangType) // impl {
}
// they should do this for unity builds
namespace clang { void foo(SomeClangType) {
}} ```
also allowing unity builds will bring more contributors, I don't contribute to clang although I would want to as I have very very long wait times that absolutely kill my motivation due to my weak laptop unity builds would help a ton
0
u/VoidVinaCC 9d ago
its just really painful to think how much compute and time is wasted on compiling/processing the same headers, templates, functions, ... a billion times and a pch generally doesnt change that either. unity build are the ONLY actual functional and efficient way of building c++ today. modules dont count because they dont work most of the time and require a lot more work to get spec compliant
1
u/_Noreturn 5d ago
Try thinking how much time is spent on computing useless strlen calls when you already know the string length :p
But yes I agree, unity builds are a blessing and are the fastest way to build, they surpass pch and modules all together
1
4
1
1
u/TheRavagerSw 10d ago
It is very buggy though, unless your are contributing you should disable PCH via cmake
3
u/babygnu42 8d ago
If you have any concrete bug, please open an issue on GitHub so that people get a chance to fix it!
0
-8
45
u/matthieum 9d ago
Anyone would jump at a 6.75% performance improvement. Right?
What I find particularly interesting here, is that looking at the breakdown, most of the optimizations are tiny. Apart from the DenseMap change (-1.27%), it's mostly -0.x% improvements, and some are even -0.0x%!
Imagine working for hours, only to shave off a measly 0.02%. It feels pretty unrewarding... no? And yet, relentlessly chipping at it -- 0.02%, 0.03%, or 0.04% at a time -- over the release cycle, at the end you get to a massive 6.75% speed improvement.
My deep thanks to the tireless contributors, who make development faster down the line.