r/cpp • u/tartaruga232 MSVC user, r/cpp_modules • May 26 '26
[std-proposals] Benchmarking using the standard library as a module
https://lists.isocpp.org/std-proposals/att-18441/attachmentSome interesting benchmarks that were posted on the [std-proposals] mailing list.
The link to the entry in the mailing list archive of [std-proposals]:
https://lists.isocpp.org/std-proposals/2026/05/18441.php
For comparison:
For our modularized Windows app1, we see a reduction in build time for a full build from ~3 to ~2 minutes due to using "import std"2.
1Using the MSVC compiler with MSBuild. We currently have 1148 C++ source files, 558 containing "export module". We have 4223 imports, 357 of these are "import std".
2A while ago (~2 months), I made an experimental branch in our (closed) source code repository, which replaces every single "import std" with the minimally required #includes of the standard library headers. That was done in our fully modularized code base.
12
u/azswcowboy May 26 '26
Here’s the table in the link with the numbers being ‘build import std module’, ‘build using import std’, and ‘build empty program with includes’:
This looks like a healthy improvement for non trivial projects, where trivial is less than a handful of translation units. If we take gcc16 I’d need to compile about 3 tests to make back the initial 3345ms compile for import std. Every other compiler it would be less. Note, the fact gcc is slower probably isn’t surprising as it’s the latest compiler to the modules party - it also has the largest standard library in 16 because it adds reflection and lots of other 26 things.
The tldr here is that this largely confirms the Microsoft study pre-standard of the expected gains. Of course there’s also just the reduced mental load for programmers trying to remember the ‘physical header architecture’ of the standard for no reason: is that in algorithm or ranges? Don’t care ‘import std’.
6
u/scrumplesplunge May 26 '26
Another thing worth noting is that the speedup also depends on what you actually use, too. If you use something template heavy, parsing matters less. As an example:
If I touch this file and rebuild it on my machine, it takes about 100ms on average.
This one takes 300ms:
This one takes 980ms:
This one takes 1250ms:
If I replace the
import stdwith four#includedirectives in that last example, it takes 1650ms. Modules are only shaving off 25% there.(timing taken with cmake 4.3.1, ninja 1.13.2, gcc 15.2.1)
1
u/kronicum May 26 '26
Why use MSBuild and not Ninja via CMake?
0
u/Nicksaurus May 26 '26
I'm guessing you're using visual studio then? Do the IDE features work well with modules? My experience with clang + vscode + clangd is that it's still basically unusable because clangd constantly crashes when you have a module file open and even when it doesn't crash it gets confused about where definitions were imported from or if they're even imported at all
It feels like it's almost ready though, I think we'll start to see modules adopted properly in 'real' codebases within the next year or two, which will be huge
1
u/_Noreturn May 27 '26
Interesting thanks for benchmarking!
1
u/Jardik2 May 28 '26
I still don't see any advantages in them over pch in terms of compilation times. Plus we use tons of other 3rd party libs, which won't see modules any time soon. And then add not working intellisense, making programmers slower. For me, the modules were a rushed mistake and I am personally avoiding them as much as possible.
-2
u/SuperV1234 https://romeo.training | C++ Mentoring & Consulting May 26 '26
I am not that impressed.
It's a welcome improvement, but nothing groundbreaking -- I would like to see how PCHs (with and without unity builds) compare, and I suspect they'd be highly competitive.
BTW, was a compilation time trace via something like
-ftime-tracein Clang measured before switching to modules? Often, just restructuring headers alone and applying some forward declarations in expensive nodes of the header graph can easily shave off minutes.