dotnet / dotnet/aspnetcore

NativeAOT is much slower that JIT version

Open
#42,221 19 comments 1 reaction 0 assignees View on GitHub
area-mvc NativeAOT Perf
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 6h
Merged PRs (30d)
290

Description

A simple REST server as below, shows that NativeAOT is much slower than JIT version of the code.

Here is the the only controller in the app :
```csharp
using Microsoft.AspNetCore.Mvc;
namespace nativeAOTapi.Controllers;

[Controller]
[Route("api/[controller]")]
public class TimeAPI :Controller
{
[HttpGet]
[Route("time")]
public ActionResult GetTime()
{
return DateTimeOffset.Now.ToUnixTimeMilliseconds();
}
}
```
Here is Program.cs:
```csharp
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
var app = builder.Build();
app.UseSwagger();
app.UseSwaggerUI();
app.MapControllers();
app.Run();
```
Here is Program.csproj
```xml


net6.0
enable
enable
Speed




```
Here is Nuget.config:

```xml







```

JIT version runs on port `5247`
NativeAOT version runs on port `5000`

Here is some benchmark results;

for JIT:
```
Bombarding http://localhost:5247/api/TimeAPI/time for 10s using 200 connection(s)
[========================================================================================================================================================================================] 10s
Done!
Statistics Avg Stdev Max
Reqs/sec 175618.11 38073.63 219971.12
Latency 1.14ms 2.07ms 192.43ms
HTTP codes:
1xx - 0, 2xx - 1749150, 3xx - 0, 4xx - 0, 5xx - 0
others - 0
Throughput: 41.53MB/s

```
for NativeAOT

```
Bombarding http://localhost:5000/api/TimeAPI/time for 10s using 200 connection(s)
[========================================================================================================================================================================================] 10s
Done!
Statistics Avg Stdev Max
Reqs/sec 51621.50 7439.70 60899.66
Latency 3.89ms 2.25ms 148.00ms
HTTP codes:
1xx - 0, 2xx - 514153, 3xx - 0, 4xx - 0, 5xx - 0
others - 0
Throughput: 12.21MB/s

```
JIT version is build and run with `dotnet run`
NativeAOT version is build with `dotnet publish -r linux-x64 -c Release`

dotnet : `6.0.101`
OS : `Linux pop-os 5.15.11-76051511-generic #202112220937~1640185481~21.10~b3a2c21 SMP Wed Dec 22 15:41:49 U x86_64 x86_64 x86_64 GNU/Linux
`
CPU : `Intel Core i7 8700`

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.