r/cpp • 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/attachment

Some 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.

28 Upvotes

29 comments sorted by

View all comments

Show parent comment

2

u/azswcowboy May 27 '26

I wonder how much of this is variadic templates. I’ve noticed, but not scientifically measured, that TUs with a fair number of variadics build slower. Mind you, we use std:format or fmt::format or spdlog (basically fmt) pretty much everywhere - and some seem to be worse that others.

4

u/scrumplesplunge May 27 '26

I think variadics themselves aren't really that bad but what is bad is the recursive O(n^2) template expansion you have to do in a lot of cases to implement things with them. I think std::variant has O(n^2) instantiation cost for many operators and I had one case at work where replacing a single variant with 100 alternatives literally cut our whole projects build time in half (15 minutes -> under 8).

With constexpr/consteval slowly getting more powerful, and especially with reflection landing in C++26, I think it's possible that there will be simpler and much faster (to compile) implementations possible for many of these things.