Skip to content

Commit 6e4fa67

Browse files
[CSharp] Add back AOT version of platform benchmarks (#8671)
* Add back AOT version of platform benchmarks These were deleted in #8498 as "Kept for future PRs for simplicity" but the future is now. * Skip fortunes benchmark Looks like RazorSlices nuget got a lot worse between 0.3.0 and 0.7.0.
1 parent 01c8d30 commit 6e4fa67

File tree

6 files changed

+70
-1
lines changed

6 files changed

+70
-1
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
2+
RUN apt-get update
3+
RUN apt-get -yqq install clang zlib1g-dev
4+
WORKDIR /app
5+
COPY src/Platform .
6+
RUN dotnet publish -c Release -o out /p:DatabaseProvider=Npgsql /p:PublishAot=true /p:OptimizationPreference=Speed /p:GarbageCollectionAdaptationMode=0
7+
8+
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS runtime
9+
ENV URLS http://+:8080
10+
11+
WORKDIR /app
12+
COPY --from=build /app/out ./
13+
COPY appsettings.postgresql.json ./appsettings.json
14+
15+
EXPOSE 8080
16+
17+
ENTRYPOINT ["./Platform"]

frameworks/CSharp/aspnetcore/benchmark_config.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,28 @@
2525
"display_name": "ASP.NET Core [Platform, Pg]",
2626
"notes": ""
2727
},
28+
"aot": {
29+
"plaintext_url": "/plaintext",
30+
"json_url": "/json",
31+
"db_url": "/db",
32+
"query_url": "/queries/",
33+
"update_url": "/updates/",
34+
"cached_query_url": "/cached-worlds/",
35+
"port": 8080,
36+
"approach": "Realistic",
37+
"classification": "Platform",
38+
"database": "Postgres",
39+
"framework": "ASP.NET Core",
40+
"language": "C#",
41+
"orm": "Raw",
42+
"platform": ".NET",
43+
"flavor": "NativeAOT",
44+
"webserver": "Kestrel",
45+
"os": "Linux",
46+
"database_os": "Linux",
47+
"display_name": "ASP.NET Core [Platform, Pg, AOT]",
48+
"notes": ""
49+
},
2850
"minimal": {
2951
"plaintext_url": "/plaintext",
3052
"json_url": "/json",

frameworks/CSharp/aspnetcore/config.toml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,23 @@ platform = ".NET"
1919
webserver = "Kestrel"
2020
versus = "None"
2121

22+
[aot]
23+
urls.plaintext = "/plaintext"
24+
urls.json = "/json"
25+
urls.db = "/db"
26+
urls.query = "/queries/"
27+
urls.update = "/updates/"
28+
urls.cached_query = "/cached-worlds/"
29+
approach = "Realistic"
30+
classification = "Platform"
31+
database = "Postgres"
32+
database_os = "Linux"
33+
os = "Linux"
34+
orm = "Raw"
35+
platform = ".NET"
36+
webserver = "Kestrel"
37+
versus = "None"
38+
2239
[minimal]
2340
urls.plaintext = "/plaintext"
2441
urls.json = "/json"

frameworks/CSharp/aspnetcore/src/Platform/BenchmarkApplication.Fortunes.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4+
#if !AOT
45
using System.IO.Pipelines;
56
using System.Runtime.CompilerServices;
67
using System.Threading.Tasks;
@@ -64,3 +65,4 @@ private static void EndTemplateRendering(ChunkedBufferWriter<WriterAdapter> chun
6465
template.Dispose();
6566
}
6667
}
68+
#endif

frameworks/CSharp/aspnetcore/src/Platform/BenchmarkApplication.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
using System.Threading.Tasks;
1111
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http;
1212
using Microsoft.Extensions.ObjectPool;
13+
#if !AOT
1314
using RazorSlices;
15+
#endif
1416

1517
namespace PlatformBenchmarks
1618
{
@@ -54,10 +56,12 @@ public bool Return(ChunkedBufferWriter<WriterAdapter> writer)
5456
}
5557
}
5658

59+
#if !AOT
5760
#if NPGSQL
5861
private readonly static SliceFactory<List<FortuneUtf8>> FortunesTemplateFactory = RazorSlice.ResolveSliceFactory<List<FortuneUtf8>>("/Templates/FortunesUtf8.cshtml");
5962
#else
6063
private readonly static SliceFactory<List<FortuneUtf16>> FortunesTemplateFactory = RazorSlice.ResolveSliceFactory<List<FortuneUtf16>>("/Templates/FortunesUtf16.cshtml");
64+
#endif
6165
#endif
6266

6367
[ThreadStatic]
@@ -163,7 +167,9 @@ private bool ProcessRequest(ref BufferWriter<WriterAdapter> writer)
163167

164168
private Task ProcessRequestAsync() => _requestType switch
165169
{
170+
#if !AOT
166171
RequestType.FortunesRaw => FortunesRaw(Writer),
172+
#endif
167173
RequestType.SingleQuery => SingleQuery(Writer),
168174
RequestType.Caching => Caching(Writer, _queries),
169175
RequestType.Updates => Updates(Writer, _queries),

frameworks/CSharp/aspnetcore/src/Platform/Platform.csproj

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<IsTestAssetProject>true</IsTestAssetProject>
77
<LangVersion>preview</LangVersion>
88
<UserSecretsId>38063504-d08c-495a-89c9-daaad2f60f31</UserSecretsId>
9+
<DefineConstants Condition="'$(PublishAot)' == 'true'">AOT;$(DefineConstants)</DefineConstants>
910
</PropertyGroup>
1011

1112
<PropertyGroup>
@@ -21,7 +22,11 @@
2122
<PackageReference Include="Npgsql" Version="8.0.1" />
2223
<PackageReference Include="MySqlConnector" Version="2.3.1" />
2324
<PackageReference Include="Dapper" Version="2.1.21" />
24-
<PackageReference Include="RazorSlices" Version="0.7.0" />
25+
<PackageReference Include="RazorSlices" Version="0.7.0" Condition="$(PublishAot) != 'true'" />
2526
</ItemGroup>
2627

28+
<PropertyGroup Condition="$(PublishAot) == 'true'">
29+
<DefaultItemExcludes>$(MSBuildThisFileDirectory)Templates/**;$(DefaultItemExcludes)</DefaultItemExcludes>
30+
</PropertyGroup>
31+
2732
</Project>

0 commit comments

Comments
 (0)