Skip to content

Conversation

@MichalStrehovsky
Copy link
Member

For native AOT we document three build modes: a blended default, optimized for size, and optimized for speed.

Typically, optimize for speed is needed to get as closed as possible to CoreCLR-JIT performance (e.g. optimize for speed is the only mode that enables Tier-1 inliner in the JIT). The blended default gets close, but this gives an extra percent or two in throughput at the cost of more size.

The VXSort code and table costs 115,712 bytes.

We currently compile with VXSort enabled in blended mode and when we optimize for speed. We link out VXSort when optimizing for size. Maybe this is not something that should be part of the blended default.

  • When you do dotnet new console --aot and dotnet publish the hello world, 11% of the output binary is VXSort (!)
  • Even in more significant apps (e.g. a simple Kestrel host), VxSort is still a single-digit percentage of the app.
  • I was not able to measure improvement with VxSort on real world apps that I tried (native AOT compiled ILC, benchmarks we use in ASP.NET labs). I'm sure there's apps in hyperscale environments that benefit, but maybe those would choose Speed optimized without even trying anything else.

I'm leaning towards disabling this on blended builds.

Our default guidance if someone is not happy with native AOT TP is to switch to Speed optimized builds, so if there's a problem because of this being off, our default guidance would resolve this right away without even having to profile and root cause the problem to sorting. I think using VxSort in the Speed optimization mode only is the right default.

Cc @dotnet/ilc-contrib @dotnet/gc

For native AOT we [document](https://learn.microsoft.com/en-us/dotnet/core/deploying/native-aot/optimizing) three build modes: a blended default, optimized for size, and optimized for speed.

Typically, optimize for speed is needed to get as closed as possible to CoreCLR-JIT performance (e.g. optimize for speed is the only mode that enables Tier-1 inliner in the JIT). The blended default gets close, but this gives an extra percent or two in throughput at the cost of more size.

The VXSort code and table costs 115,712 bytes.

We currently compile with VXSort enabled in blended mode and optimize for speed. We link out VXSort when optimizing for size. Maybe this is not something that should be part of the blended default.

* When you do `dotnet new console --aot` and `dotnet publish` the hello world, 11% of the output binary is VXSort (!)
* Even in more significant apps (e.g. a simple Kestrel host), VxSort is still a single-digit percentage of the app.
* I was not able to measure improvement with VxSort on real world apps that I tried (native AOT compiled ILC, benchmarks we use in ASP.NET labs).

I'm leaning towards disabling this on blended builds.

Our default guidance if someone is not happy with native AOT TP is to switch to Speed optimized builds, so if there's a problem because of this being off, our default guidance would resolve this right away without even having to profile and root cause the problem to sorting. I think using VxSort in the Speed optimization mode only is the right default.
Copilot AI review requested due to automatic review settings August 12, 2025 10:49
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR flips the default behavior for VXSort in native AOT compilation by disabling it in the default blended mode and only enabling it when explicitly optimizing for speed. The change addresses concerns about binary size impact - VXSort adds 115KB and can represent 11% of a hello world native AOT binary.

Key changes:

  • Changes default VXSort behavior from enabled to disabled in blended optimization mode
  • VXSort now only enables when OptimizationPreference is set to Speed or when explicitly enabled via IlcEnableVxsort
  • Replaces the size-optimization exclusion logic with speed-optimization inclusion logic

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
Microsoft.NETCore.Native.Windows.targets Updates Windows native AOT build logic to disable VXSort by default and enable only for speed optimization
Microsoft.NETCore.Native.Unix.targets Updates Unix native AOT build logic to disable VXSort by default and enable only for speed optimization

@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas
See info in area-owners.md if you want to be subscribed.

@jkotas
Copy link
Member

jkotas commented Aug 12, 2025

Makes sense to me. The binary size test needs updating.

@MichalStrehovsky
Copy link
Member Author

The binary size test needs updating.

Good problem to have!

@mangod9
Copy link
Member

mangod9 commented Aug 12, 2025

I was not able to measure improvement with VxSort on real world apps that I tried (native AOT compiled ILC, benchmarks we use in ASP.NET labs). I'm sure there's apps in hyperscale environments that benefit, but maybe those would choose Speed optimized without even trying anything else.

VxSort is helpful for apps with heavy allocations per request, dont think the standard asp.net benchmarks will show any benefits. Agree to keep it off by default -- do we know the split of apps built with blended, speed or size?

@MichalStrehovsky
Copy link
Member Author

VxSort is helpful for apps with heavy allocations per request, dont think the standard asp.net benchmarks will show any benefits. Agree to keep it off by default -- do we know the split of apps built with blended, speed or size?

The best I have is a non-scientific Github search:

So about 1% of users set Speed, 1% set Size and 98% leave at the default.

@MichalStrehovsky MichalStrehovsky merged commit 4faabd3 into dotnet:main Aug 13, 2025
94 of 97 checks passed
@MichalStrehovsky MichalStrehovsky deleted the avxsort branch August 13, 2025 04:58
@github-actions github-actions bot locked and limited conversation to collaborators Sep 12, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants