Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build/dependencies.props
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<MicrosoftIISTestingVersion100>10.0.0-*</MicrosoftIISTestingVersion100>

<DapperVersion>2.1.35</DapperVersion>
<RazorSlicesVersion>0.7.0</RazorSlicesVersion>
<RazorSlicesVersion>0.8.1</RazorSlicesVersion>
<SystemCommandLineVersion>2.0.0-beta4.22272.1</SystemCommandLineVersion>
<MicrosoftCrankEventSourcesVersion>0.2.0-alpha.24114.2</MicrosoftCrankEventSourcesVersion>
<OpenTelemetryVersion>1.9.0</OpenTelemetryVersion>
Expand Down
2 changes: 1 addition & 1 deletion src/Benchmarks/Benchmarks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="$(MicrosoftEntityFrameworkCoreSqlServerVersion90)" />
<PackageReference Include="Microsoft.Data.SqlClient" Version="$(MicrosoftDataSqlClientVersion90)" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="$(MicrosoftEntityFrameworkCoreSqliteVersion90)" />
<PackageReference Include="Microsoft.AspNetCore.Server.IntegrationTesting.IIS" Version="$(MicrosoftAspNetCoreAppPackageVersion)" />
<PackageReference Include="Microsoft.AspNetCore.Server.IntegrationTesting.IIS" Version="$(MicrosoftIISTestingVersion90)" />
Copy link
Member Author

Choose a reason for hiding this comment

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

Seems this was a typo/copy-pasta that was causing a NuGet warning as the versions didn't line up.

</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/BenchmarksApps.sln
Original file line number Diff line number Diff line change
Expand Up @@ -266,12 +266,12 @@ Global
{8DF3A6BB-E8C5-4FAA-839A-D185C9F93CD5} = {D8A014FB-3C99-4831-9FFB-F4A89A48D8BD}
{9E4AF835-2A78-4012-B0B5-9DA41ACDC716} = {D8A014FB-3C99-4831-9FFB-F4A89A48D8BD}
{20757830-EA66-4962-BDBB-A101A2062A2C} = {D8A014FB-3C99-4831-9FFB-F4A89A48D8BD}
{07C0B18B-9738-4349-A8DF-3E88D3DF90AE} = {9E4AF835-2A78-4012-B0B5-9DA41ACDC716}
{07C0B18B-9738-4349-A8DF-3E88D3DF90AE} = {B6DB234C-8F80-4160-B95D-D70AFC444A3D}
{E68B58F8-40EA-49EA-A126-0B67F2BE7343} = {B6DB234C-8F80-4160-B95D-D70AFC444A3D}
{ACA43671-AD28-4F72-AAAB-6C32B388C2F0} = {B6DB234C-8F80-4160-B95D-D70AFC444A3D}
{D8F11F87-823F-4864-926D-5F66448A5C13} = {B6DB234C-8F80-4160-B95D-D70AFC444A3D}
{3D2573DE-CE7A-4CB8-A980-8C8636EE059E} = {398A40DA-FE1D-4B4D-A580-A33E29885553}
{31B61CD7-4CF6-464F-B418-04C700A17CB9} = {6A69DE6C-07A6-4ABE-A4D2-0F983A33BBF8}
{31B61CD7-4CF6-464F-B418-04C700A17CB9} = {B6DB234C-8F80-4160-B95D-D70AFC444A3D}
{D6616E03-A2DA-4929-AD28-595ECC4C004D} = {B6DB234C-8F80-4160-B95D-D70AFC444A3D}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
Expand Down
4 changes: 2 additions & 2 deletions src/BenchmarksApps/DistributedCache/DistributedCache.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<OutputType>Exe</OutputType>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
Expand Down
6 changes: 5 additions & 1 deletion src/BenchmarksApps/Grpc/GrpcHttpApiServer/Server/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Console;

namespace Server
{
Expand Down Expand Up @@ -84,7 +85,10 @@ public static IHostBuilder CreateHostBuilder(string[] args)
if (Enum.TryParse<LogLevel>(config["LogLevel"], out var logLevel))
{
Console.WriteLine($"Console Logging enabled with level '{logLevel}'");
loggerFactory.AddConsole(o => o.TimestampFormat = "ss.ffff ").SetMinimumLevel(logLevel);
loggerFactory
.AddConsole()
.AddConsoleFormatter<ConsoleFormatter, ConsoleFormatterOptions>(o => o.TimestampFormat = "ss.ffff")
Copy link
Member Author

Choose a reason for hiding this comment

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

This change was done to resolve an obsolete warning.

.SetMinimumLevel(logLevel);
}
})
.UseDefaultServiceProvider((context, options) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<ItemGroup>
<PackageReference Include="Grpc.AspNetCore" Version="2.27.0" />
<PackageReference Include="Microsoft.AspNetCore.Grpc.HttpApi" Version="0.1.0-alpha.20121.1" />
<PackageReference Include="Microsoft.AspNetCore.Grpc.HttpApi" Version="0.1.0-alpha.20179.2" />
Copy link
Member Author

Choose a reason for hiding this comment

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

This was done to quiet a NuGet warning about the previous stated version being unresolvable.

</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/BenchmarksApps/HelloWorldMvc/HelloWorldMvc.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<OutputType>Exe</OutputType>
</PropertyGroup>
</Project>
4 changes: 2 additions & 2 deletions src/BenchmarksApps/MapAction/MapAction.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>
</Project>
2 changes: 1 addition & 1 deletion src/BenchmarksApps/SignalR/BenchmarkServer.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/BenchmarksApps/TechEmpower/BlazorSSR/BlazorSSR.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<PackageReference Include="Npgsql" Version="$(NpgsqlVersion80)" />
</ItemGroup>

<ItemGroup Condition="$([MSBuild]::VersionGreaterThanOrEquals($(TargetFrameworkVersion), '9.0'))">
<ItemGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible($(TargetFramework), 'net9.0'))">
Copy link
Member Author

Choose a reason for hiding this comment

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

This fixes a build error that occurs when building the project without specifying a target framework, e.g. when building from VS 😄

<PackageReference Include="Npgsql" Version="$(NpgsqlVersion90)" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="$(NpgsqlEntityFrameworkCorePostgreSQLVersion90)" />
</ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/BenchmarksApps/TechEmpower/Minimal/Minimal.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<LangVersion>latest</LangVersion>
Expand All @@ -14,7 +14,7 @@
<PackageReference Include="RazorSlices" Version="$(RazorSlicesVersion)" />
</ItemGroup>

<ItemGroup Condition="$([MSBuild]::VersionGreaterThanOrEquals($(TargetFrameworkVersion), '9.0'))">
<ItemGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible($(TargetFramework), 'net9.0'))">
<PackageReference Include="Npgsql" Version="$(NpgsqlVersion90)" />
</ItemGroup>
</Project>
4 changes: 2 additions & 2 deletions src/BenchmarksApps/TechEmpower/Minimal/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Minimal;
using Minimal.Database;
using Minimal.Models;
using Minimal.Templates;

var builder = WebApplication.CreateBuilder(args);

Expand Down Expand Up @@ -37,12 +38,11 @@

app.MapGet("/db/result", async (Db db) => Results.Json(await db.LoadSingleQueryRow()));

var createFortunesTemplate = RazorSlice.ResolveSliceFactory<List<Fortune>>("/Templates/Fortunes.cshtml");
var htmlEncoder = CreateHtmlEncoder();

app.MapGet("/fortunes", async (HttpContext context, Db db) => {
var fortunes = await db.LoadFortunesRows();
var template = (RazorSliceHttpResult<List<Fortune>>)createFortunesTemplate(fortunes);
var template = (RazorSliceHttpResult<List<Fortune>>)Fortunes.Create(fortunes);
Copy link
Member Author

Choose a reason for hiding this comment

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

Razor Slices generates these template factory classes now.

template.HtmlEncoder = htmlEncoder;
return template;
});
Expand Down
7 changes: 1 addition & 6 deletions src/BenchmarksApps/TechEmpower/Mvc/Mvc.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,12 @@
<PackageReference Include="Dapper" Version="$(DapperVersion)" />
</ItemGroup>

<ItemGroup Condition="$(TargetFramework) == 'net7.0'">
<PackageReference Include="Npgsql" Version="$(NpgsqlVersion70)" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="$(NpgsqlEntityFrameworkCorePostgreSQLVersion70)" />
</ItemGroup>

<ItemGroup Condition="$(TargetFramework) == 'net8.0'">
<PackageReference Include="Npgsql" Version="$(NpgsqlVersion80)" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="$(NpgsqlEntityFrameworkCorePostgreSQLVersion80)" />
</ItemGroup>

<ItemGroup Condition="$([MSBuild]::VersionGreaterThanOrEquals($(TargetFrameworkVersion), '9.0'))">
<ItemGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible($(TargetFramework), 'net9.0'))">
<PackageReference Include="Npgsql" Version="$(NpgsqlVersion90)" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="$(NpgsqlEntityFrameworkCorePostgreSQLVersion90)" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace PlatformBenchmarks
{
public partial class BenchmarkApplication
public sealed partial class BenchmarkApplication
{
private static async Task Caching(PipeWriter pipeWriter, int count)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,81 +1,81 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.IO.Pipelines;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using RazorSlices;

namespace PlatformBenchmarks
namespace PlatformBenchmarks;
Copy link
Member Author

Choose a reason for hiding this comment

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

Changed to file-scoped namespace declaration on this file.


public sealed partial class BenchmarkApplication
{
public partial class BenchmarkApplication
{
#if DATABASE
private async Task FortunesRaw(PipeWriter pipeWriter)
{
await OutputFortunes(
pipeWriter,
await RawDb.LoadFortunesRows(),
// To isolate template rendering from DB access, comment out the line above and uncomment the line below
//await RawDb.LoadFortunesRowsNoDb(),
FortunesTemplateFactory);
}

private async Task FortunesDapper(PipeWriter pipeWriter)
{
await OutputFortunes(pipeWriter, await DapperDb.LoadFortunesRows(), FortunesDapperTemplateFactory);
}

private async Task FortunesEf(PipeWriter pipeWriter)
{
await OutputFortunes(pipeWriter, await EfDb.LoadFortunesRows(), FortunesEfTemplateFactory);
}
private async Task FortunesRaw(PipeWriter pipeWriter)
{
await OutputFortunes(
pipeWriter,
await RawDb.LoadFortunesRows(),
// To isolate template rendering from DB access, comment out the line above and uncomment the line below
//await RawDb.LoadFortunesRowsNoDb(),
Templates.FortunesUtf8.Create);
}

private ValueTask OutputFortunes<TModel>(PipeWriter pipeWriter, TModel model, SliceFactory<TModel> templateFactory)
{
// Render headers
var preamble = """
HTTP/1.1 200 OK
Server: K
Content-Type: text/html; charset=utf-8
Transfer-Encoding: chunked
"""u8;
var headersLength = preamble.Length + DateHeader.HeaderBytes.Length;
var headersSpan = pipeWriter.GetSpan(headersLength);
preamble.CopyTo(headersSpan);
DateHeader.HeaderBytes.CopyTo(headersSpan[preamble.Length..]);
pipeWriter.Advance(headersLength);
private async Task FortunesDapper(PipeWriter pipeWriter)
{
await OutputFortunes(pipeWriter, await DapperDb.LoadFortunesRows(), Templates.FortunesUtf8.Create);
}

// Render body
var template = templateFactory(model);
// Kestrel PipeWriter span size is 4K, headers above already written to first span & template output is ~1350 bytes,
// so 2K chunk size should result in only a single span and chunk being used.
var chunkedWriter = GetChunkedWriter(pipeWriter, chunkSizeHint: 2048);
var renderTask = template.RenderAsync(chunkedWriter, null, HtmlEncoder);
private async Task FortunesEf(PipeWriter pipeWriter)
{
await OutputFortunes(pipeWriter, await EfDb.LoadFortunesRows(), Templates.FortunesEf.Create);
}

if (renderTask.IsCompletedSuccessfully)
{
renderTask.GetAwaiter().GetResult();
EndTemplateRendering(chunkedWriter, template);
return ValueTask.CompletedTask;
}
private ValueTask OutputFortunes<TModel>(PipeWriter pipeWriter, TModel model, Func<TModel, RazorSlice> templateFactory)
{
// Render headers
var preamble = """
HTTP/1.1 200 OK
Server: K
Content-Type: text/html; charset=utf-8
Transfer-Encoding: chunked
"""u8;
var headersLength = preamble.Length + DateHeader.HeaderBytes.Length;
var headersSpan = pipeWriter.GetSpan(headersLength);
preamble.CopyTo(headersSpan);
DateHeader.HeaderBytes.CopyTo(headersSpan[preamble.Length..]);
pipeWriter.Advance(headersLength);

return AwaitTemplateRenderTask(renderTask, chunkedWriter, template);
}
// Render body
var template = templateFactory(model);
// Kestrel PipeWriter span size is 4K, headers above already written to first span & template output is ~1350 bytes,
// so 2K chunk size should result in only a single span and chunk being used.
var chunkedWriter = GetChunkedWriter(pipeWriter, chunkSizeHint: 2048);
var renderTask = template.RenderAsync(chunkedWriter, HtmlEncoder);

private static async ValueTask AwaitTemplateRenderTask(ValueTask renderTask, ChunkedBufferWriter<WriterAdapter> chunkedWriter, RazorSlice template)
if (renderTask.IsCompletedSuccessfully)
{
await renderTask;
renderTask.GetAwaiter().GetResult();
EndTemplateRendering(chunkedWriter, template);
return ValueTask.CompletedTask;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static void EndTemplateRendering(ChunkedBufferWriter<WriterAdapter> chunkedWriter, RazorSlice template)
{
chunkedWriter.End();
ReturnChunkedWriter(chunkedWriter);
template.Dispose();
}
#endif
return AwaitTemplateRenderTask(renderTask, chunkedWriter, template);
}

private static async ValueTask AwaitTemplateRenderTask(ValueTask renderTask, ChunkedPipeWriter chunkedWriter, RazorSlice template)
{
await renderTask;
EndTemplateRendering(chunkedWriter, template);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static void EndTemplateRendering(ChunkedPipeWriter chunkedWriter, RazorSlice template)
{
chunkedWriter.Complete();
ReturnChunkedWriter(chunkedWriter);
template.Dispose();
}
#endif
}
Loading