Build the STL with only /O2, not /Os#6110
Merged
StephanTLavavej merged 1 commit intomicrosoft:mainfrom Feb 28, 2026
Merged
Conversation
Member
Author
|
I'm mirroring this to the MSVC-internal repo. Please notify me if any further changes are pushed, otherwise no action is required. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2108.
The STL (and indeed the entire internal "crt" directory) was being built with
/O2 /Os. I'm convinced that this was unintentional for a really silly reason (MSBuild made it hard to see that there was a global default for/Os, which the compiler DLLs likec1xx.dllandc2.dlloverrode, but the library DLLs missed). When our build system / compiler options were ported to CMake, the usage of/O2 /Oslooked way more intentional than it was.I loathe
/Osand the old "small is fast" heuristic. The STL expects a lot of inlining for performance, so/Osis very hostile to our code. You know what's a better heuristic? "Fast is fast." Give just/O2to the compiler and let it figure out what's fastest. (Caches are also massively bigger than decades ago, so an obsessive focus on code size is not nearly as important.)Of course, removing
/Oswill increase the size of our DLLs. However, the effect isn't massive, and we've made offsetting improvements. Here are my measurements:msvcp140_oss.dllmsvcp140_1_oss.dllmsvcp140_2_oss.dllmsvcp140_atomic_wait_oss.dllmsvcp140_codecvt_ids_oss.dllmsvcp140_oss.dllmsvcp140_1_oss.dllmsvcp140_2_oss.dllmsvcp140_atomic_wait_oss.dllmsvcp140_codecvt_ids_oss.dllIn my opinion these are reasonable increases. (Reversing the status quo, if we were currently being built with
/O2, we would not be interested in pessimizing our codegen to save a bit of space here with/O2 /Os.)And as for offsetting improvements, while the STL has had a tendency to grow over time as more code is added, we've also been able to remove a lot of code by increasing our OS baseline up to Win10, plus deliberate changes like #5836. (For the VCRedist size itself, I removed entire megabytes by dropping the Win7/8/8.1 MSUs in VS 2026 / MSVC Build Tools 14.50.) See #2108 (comment) for my most recent DLL size archaeology.
So while removing
/Oswill increase DLL sizes, I believe that the impact is acceptable. For example, looking at the original STL DLL, it was 633,152 bytes in VS 2015 Update 3. That decreased to 532,048 bytes in the latest MSVC Build Tools 14.51 Preview, and this PR increases it to 653,312 - so, a little bigger than it was historically, but essentially paid for by our improvements over the years.