Skip to content

Optimize the NativeAOT CLI for size - #55733

Merged
baronfel merged 1 commit into
mainfrom
baronfel-optimize-naot-for-size
Aug 12, 2026
Merged

baronfel merged 1 commit into
mainfrom
baronfel-optimize-naot-for-size

Conversation

@baronfel

Copy link
Copy Markdown
Member

Summary

Set OptimizationPreference=Size for the NativeAOT CLI.

This setting reduces the NativeAOT binary size in exchange for a small, mostly fixed startup cost.

Benchmark results

The measurements used Release builds for win-x64 on dotnet/sdk PR #55497. The full benchmark report contains the setup and caveats.

Binary size

Build Speed Size Reduction
PR base 20.60 MiB 17.16 MiB 3.44 MiB / 16.7%
PR head 45.79 MiB 36.28 MiB 9.51 MiB / 20.8%

Invariant globalization reduced the PR-head binary by only 0.22–0.25 MiB, or approximately 0.6%. This PR does not change globalization behavior.

Most PR growth was native code and read-only data. .rdata contributed 13.09 MiB, and .text contributed 9.60 MiB.

Startup time

Each result is the median of 150 launches on the PR head.

Command Speed Size Difference
--version 27.40 ms 40.47 ms +13.07 ms
--info 55.47 ms 68.87 ms +13.40 ms
--help 27.79 ms 40.84 ms +13.05 ms
build --help 27.97 ms 41.36 ms +13.39 ms
restore --help 28.74 ms 41.89 ms +13.15 ms
sdk check 108.06 ms 117.27 ms +9.21 ms

Size optimization added approximately 9–13 ms with normal globalization. The fixed cost creates a larger percentage change for commands that do little work.

Validation

Published src/Cli/dotnet-aot/dotnet-aot.csproj for Release and win-x64. The NativeAOT compiler evaluated OptimizationPreference=Size and produced the native library.

Co-authored-by: Copilot App <[email protected]>

Copilot-Session: 44897815-78b2-4f83-a245-912dfc79eb74
Copilot AI lite review requested due to automatic review settings August 11, 2026 21:38
@baronfel
baronfel requested a review from a team as a code owner August 11, 2026 21:39
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
2 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@baronfel
baronfel requested a review from marcpopMSFT August 11, 2026 21:39
@baronfel baronfel added the Area-dotnet AOT Items that are part of the dotnet CLI AOT-ification effort label Aug 11, 2026
@baronfel baronfel self-assigned this Aug 11, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Sets the NativeAOT build for the dotnet-aot CLI project to prefer size optimizations, aiming to reduce the produced native binary size at the cost of a small, mostly fixed startup overhead.

Changes:

  • Set OptimizationPreference=Size in src/Cli/dotnet-aot/dotnet-aot.csproj to bias NativeAOT compilation toward smaller output.

@baronfel
baronfel merged commit e86710e into main Aug 12, 2026
24 checks passed
@baronfel
baronfel deleted the baronfel-optimize-naot-for-size branch August 12, 2026 16:05
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-rc1 milestone Aug 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area-dotnet AOT Items that are part of the dotnet CLI AOT-ification effort

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants