.NET application startup time and latency can be improved by compiling your application assemblies in ReadyToRun
(R2R) format. R2R is a form of ahead-of-time (AOT) compilation.
To compile your project as ReadyToRun
, the application must be published with the PublishReadyToRun
property set to true
.
To enable this, you can add the
<PropertyGroup>
<PublishReadyToRun>true</PublishReadyToRun>
</PropertyGroup>
Now run the following command to publish it.
dotnet publish -c Release -r win-x64
You can also specify the PublishReadyToRun
flag directly to the dotnet publish
command, as shown below.
dotnet publish -c Release -r win-x64 -p:PublishReadyToRun=true
Ahead-of-time compilation has a complex performance impact on application performance, which may be difficult to predict.
ReadyToRun
, as the .NET runtime libraries have already been precompiled with ReadyToRun
.The startup improvement discussed here applies not only to the application startup but also to the first use of any code in the application. For instance, ReadyToRun can be used to reduce the response latency of the first use of Web API in an ASP.NET application.