-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Add benchmarks for RDG #50266
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add benchmarks for RDG #50266
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
global using Xunit; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need this because the shared There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NIT: Can we add this explanation as a comment to this line 🙂 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,13 +6,34 @@ | |
<ServerGarbageCollection>true</ServerGarbageCollection> | ||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
<RootNamespace>Microsoft.AspNetCore.Http</RootNamespace> | ||
<PreserveCompilationContext>true</PreserveCompilationContext> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to enable this to support passing assembly info to the Roslyn compilation instance at runtime. |
||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<Reference Include="BenchmarkDotNet" /> | ||
<Reference Include="Microsoft.AspNetCore" /> | ||
<Reference Include="Microsoft.AspNetCore.Testing" /> | ||
<Reference Include="Microsoft.AspNetCore.Http" /> | ||
<Reference Include="Microsoft.AspNetCore.Http.Results" /> | ||
<Reference Include="Microsoft.AspNetCore.Http.Extensions" /> | ||
<Compile Include="$(SharedSourceRoot)BenchmarkRunner\*.cs" /> | ||
<Reference Include="Microsoft.AspNetCore.Mvc.Core" /> | ||
<Reference Include="Microsoft.Extensions.DependencyInjection" /> | ||
<Reference Include="Microsoft.Extensions.DependencyModel" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" IsImplicitlyDefined="true" Version="$(MicrosoftCodeAnalysisVersion_LatestVS)" /> | ||
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" IsImplicitlyDefined="true" Version="$(MicrosoftCodeAnalysisVersion_LatestVS)" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Compile Include="$(RepoRoot)src\Http\Http.Extensions\test\RequestDelegateGenerator\RequestDelegateCreationTestBase.cs" LinkBase="Shared" /> | ||
<Compile Include="$(RepoRoot)src\Http\Http.Extensions\test\RequestDelegateGenerator\SharedTypes.cs" LinkBase="Shared" /> | ||
<Compile Include="$(SharedSourceRoot)BenchmarkRunner\*.cs" LinkBase="Shared" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="$(RepoRoot)src\Http\Http.Extensions\gen\Microsoft.AspNetCore.Http.RequestDelegateGenerator.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
using BenchmarkDotNet.Attributes; | ||
using Microsoft.AspNetCore.Http.Generators.Tests; | ||
|
||
namespace Microsoft.AspNetCore.Http.Microbenchmarks; | ||
|
||
public class RequestDelegateGeneratorBenchmarks : RequestDelegateCreationTestBase | ||
{ | ||
protected override bool IsGeneratorEnabled => true; | ||
|
||
[Params(10, 100, 1000, 10000)] | ||
public int EndpointCount { get; set; } | ||
|
||
private string _source; | ||
|
||
[GlobalSetup] | ||
public void Setup() | ||
{ | ||
_source = ""; | ||
for (var i = 0; i < EndpointCount; i++) | ||
{ | ||
_source += $"""app.MapGet("/route{i}", (int? id) => "Hello World!");"""; | ||
} | ||
} | ||
|
||
[Benchmark] | ||
public async Task CreateRequestDelegate() | ||
{ | ||
await RunGeneratorAsync(_source); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just curious: which internal types do we need this for? I had assumed that RunGenerator should just work by passing it a source and the generator.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
RequestDelegateCreationTestBase
class that I'm source-sharing between our integration tests and our benchmarks dependencies on some types that are internal to the generator (e.g. theEndpoint
type which represents the info we've derived vai Roslyn about a method invocation that maps to a minimal API).I could've done work work to factor out the RequestDelegateCreationTestBase class here but I figured there was no harm in doing IVT between our benchmarks and generator.
Also, it'll help in the future if we decide to profile specific parts of the generator implementation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, thanks for the explanation. I know other repos like dotnet/runtime try to avoid IVT for these cases and prefer source sharing instead but I think both approaches are fine 😃