r/cpp • u/cpppm MSVC Game Dev PM • Mar 04 '26
C++ Performance Improvements in MSVC Build Tools v14.51
https://devblogs.microsoft.com/cppblog/c-performance-improvements-in-msvc-build-tools-v14-51/#unpacking-struct-assignments-with-casted-fields
113
Upvotes
47
u/STL MSVC STL Dev Mar 04 '26
A few notes:
<flat_map>,<flat_set>,reference_meows_from_temporary, andis_implicit_lifetimehave all been added between 14.51 Preview and General Availability.27
u/tartaruga232 MSVC user, r/cpp_modules Mar 04 '26
Congrats! Who said Microsoft stopped investing in C++?
11
u/Kronikarz Mar 05 '26
Unfortunately the link seems to no longer work (at least for me).
10
u/augustinpopa Microsoft C++ PM (IDE & vcpkg) Mar 05 '26
Hey folks, we had to take the blog down temporarily to correct a few issues that were called out to us. It should be back up shortly. Sorry for the inconvenience.
5
u/slithering3897 Mar 06 '26 edited Mar 06 '26
Yes, I think I got a few percentage points of improvement, but it's still a long way to go to catch up to clang-cl.
Keep an eye on
<simd>. That's what clang-cl is so much better at for me: SIMD abstractions. Not just a little bit, a lot. It's much better at inlining. I've got a routine that's just littered with calls when using MSVC, but the clang-cl version is a beautiful monolithic blob of AVX.*Also, it would be nice if I could just use clang-cl for everything, but I can't with modules, and it has debugging difficulties for some reason.
4
u/ReDucTor Game Developer | quiz.cpp-perf.com Mar 05 '26
Awesome work, looking at some of these, there is still more room for improvement
Unpacking Struct Assignments with Casted Fields
New Optimized:
Further optimized: this could potentially do an
addwith the load and earlier before thecalleliminating the need for preservingrdiandrbxUnpacking Struct Assignments with Source Struct at Non-Zero Offset
New Optimized:
This could do a
qwordstore fors1->iands1->jBranch Elimination
Depending on the usage this could also lead to loop carried dependency, how do you avoid this situation?
7
u/Tringi github.com/tringi Mar 04 '26 edited Mar 14 '26
I could swear I've seen some of these optimizations while reading GCC docs some 15 years ago. Still, I'm happy to see them being finally added to MSVC which is my bread and butter today.
A question: Does Repacking Struct Assignments with Indirections work the same for non-homogeneous structures?
EDIT: I'll answer my own question: Yes it does, when the structure is tightly packed, i.e. no padding bytes. Also it requires
/GS-.4
u/James20k P2005R0 Mar 04 '26
As a piece of feedback on the site: when the window is narrow, the table of contents jumps to the top and causes the scrolling to skip, which can make the opening section very jittery to read
6
u/JVApen Clever is an insult, not a compliment. - T. Winters Mar 04 '26
That's a lot of work for fixing legacy code. You could wonder what else could have been done in the same time. In my measurements from a while ago, clang-cl outperformed msvc significantly, both in compilation and runtime speed. So why would they not have moved to an LLVM backend? Especially since they are already using SSA according to the article. Intel did a while go and they showed both performance gains compared to their old compiler and the vanilla clang compiler.
MS already implemented clang+c2 a long time ago where they did the inverse. Clang frontend, MSVC backend with a translation of LLVM IR (SSA). Since that time, llvm improved it's binary compatibility with MSVC by a lot. And who would be better placed to validate that compatibility and fix leftover issues? An extra argument for MS management, the official rust compiler for windows also uses the LLVM backend.
Am I greatly under/overestimating the complexity? Am I missing some functional blockers here? Or does MS protect itself by being the one that defines the ABI instead of combined efforts in LLVM?
3
u/Zeh_Matt No, no, no, no Mar 06 '26
Gated behind VS 2026, still utterly annoyed by this.
1
u/Careless_Bag2568 Mar 04 '26
Top
1
u/Remnant44 Mar 08 '26
I absolutely love this. The reluctance of MSVC to inline single-use lambdas is really painful, because the pattern of taking a lambda to apply as a visitor to a set of data is one that I use heavily, and the lack of inline is not only slow on its own, but also inhibits all kinds of other potential optimizations like auto vectorization. Basically I've never seen MSVC actually autovectorize my production code because of issues like this - so I'm looking forward to the change