-
-
Notifications
You must be signed in to change notification settings - Fork 431
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #791 from Cysharp/vNext
MagicOnion 7.0
- Loading branch information
Showing
272 changed files
with
10,770 additions
and
2,839 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ on: | |
push: | ||
branches: | ||
- main | ||
- vNext | ||
tags: | ||
- "!*" # not a tag push | ||
paths-ignore: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
BenchmarkDotNet.Artifacts |
37 changes: 37 additions & 0 deletions
37
perf/Microbenchmark/Microbenchmark.Client/ChannelAsyncStreamReader.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using System.Runtime.CompilerServices; | ||
using System.Threading.Channels; | ||
using Grpc.Core; | ||
|
||
namespace Microbenchmark.Client; | ||
|
||
class ChannelAsyncStreamReader<T> : IAsyncStreamReader<T> | ||
{ | ||
readonly ChannelReader<T> reader; | ||
|
||
public T Current { get; private set; } = default!; | ||
|
||
public ChannelAsyncStreamReader(Channel<T> channel) | ||
{ | ||
reader = channel.Reader; | ||
} | ||
|
||
public Task<bool> MoveNext(CancellationToken cancellationToken) | ||
{ | ||
return MoveNextCore(cancellationToken).AsTask(); | ||
} | ||
|
||
[AsyncMethodBuilder(typeof(PoolingAsyncValueTaskMethodBuilder<>))] | ||
async ValueTask<bool> MoveNextCore(CancellationToken cancellationToken) | ||
{ | ||
if (await reader.WaitToReadAsync()) | ||
{ | ||
if (reader.TryRead(out var item)) | ||
{ | ||
Current = item; | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
perf/Microbenchmark/Microbenchmark.Client/ChannelClientStreamWriter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using System.Threading.Channels; | ||
using Grpc.Core; | ||
|
||
namespace Microbenchmark.Client; | ||
|
||
class ChannelClientStreamWriter<T> : IClientStreamWriter<T> | ||
{ | ||
readonly ChannelWriter<T> writer; | ||
|
||
public WriteOptions? WriteOptions { get; set; } | ||
|
||
public ChannelClientStreamWriter(ChannelWriter<T> writer) | ||
{ | ||
this.writer = writer; | ||
} | ||
|
||
public Task CompleteAsync() | ||
{ | ||
writer.Complete(); | ||
return Task.CompletedTask; | ||
} | ||
|
||
public Task WriteAsync(T message) | ||
{ | ||
writer.TryWrite(message); | ||
return Task.CompletedTask; | ||
} | ||
} |
82 changes: 82 additions & 0 deletions
82
perf/Microbenchmark/Microbenchmark.Client/HubMethodBenchmarks.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
using BenchmarkDotNet.Attributes; | ||
using MagicOnion.Client.DynamicClient; | ||
|
||
namespace Microbenchmark.Client; | ||
|
||
[MemoryDiagnoser, RankColumn] | ||
[ShortRunJob] | ||
public class HubMethodBenchmarks | ||
{ | ||
readonly StreamingHubClientTestHelper<ITestHub, ITestHubReceiver> helper; | ||
readonly Task responseTask; | ||
readonly ITestHub client; | ||
|
||
static ReadOnlySpan<byte> IntResponse => [0xcd, 0x30, 0x39 /* 12345 (int) */]; | ||
static ReadOnlySpan<byte> NilResponse => [0xc0 /* Nil */]; | ||
static ReadOnlySpan<byte> StringResponse => [0xa6, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x21 /* "Hello!" (string) */]; | ||
|
||
public HubMethodBenchmarks() | ||
{ | ||
this.helper = new StreamingHubClientTestHelper<ITestHub, ITestHubReceiver>(new TestHubReceiver(), DynamicStreamingHubClientFactoryProvider.Instance); | ||
this.responseTask = Task.Run(async () => | ||
{ | ||
while (true) | ||
{ | ||
var req = await helper.ReadRequestNoDeserializeAsync(); | ||
if (req.MethodId is -2087943100 or 1273874383) | ||
{ | ||
// Parameter_Zero_Return_ValueType, Parameter_Many_Return_ValueType | ||
helper.WriteResponse(req.MessageId, req.MethodId, IntResponse); | ||
} | ||
else if (req.MethodId is -1841486598) | ||
{ | ||
// ValueTask_Parameter_Zero_NoReturn | ||
helper.WriteResponse(req.MessageId, req.MethodId, NilResponse); | ||
} | ||
else if (req.MethodId is -440496944 or -1110031569) | ||
{ | ||
// Parameter_Zero_Return_RefType, Parameter_Many_Return_RefType | ||
helper.WriteResponse(req.MessageId, req.MethodId, StringResponse); | ||
} | ||
} | ||
}); | ||
this.client = helper.ConnectAsync().GetAwaiter().GetResult(); | ||
} | ||
|
||
[Benchmark] | ||
public Task Void_Parameter_Zero_NoReturn() | ||
{ | ||
client.Void_Parameter_Zero_NoReturn(); | ||
return Task.CompletedTask; | ||
} | ||
|
||
[Benchmark] | ||
public async Task ValueTask_Parameter_Zero_NoReturn() | ||
{ | ||
await client.ValueTask_Parameter_Zero_NoReturn(); | ||
} | ||
|
||
[Benchmark] | ||
public async Task Parameter_Zero_Return_ValueType() | ||
{ | ||
var value = await client.Parameter_Zero_Return_ValueType(); | ||
} | ||
|
||
[Benchmark] | ||
public async Task Parameter_Many_Return_ValueType() | ||
{ | ||
var value = await client.Parameter_Many_Return_ValueType("Hello", 12345, true); | ||
} | ||
|
||
[Benchmark] | ||
public async Task Parameter_Zero_Return_RefType() | ||
{ | ||
var value = await client.Parameter_Zero_Return_RefType(); | ||
} | ||
|
||
[Benchmark] | ||
public async Task Parameter_Many_Return_RefType() | ||
{ | ||
var value = await client.Parameter_Many_Return_RefType("Hello", 12345, true); | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
perf/Microbenchmark/Microbenchmark.Client/HubReceiverBroadcastBenchmarks.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
using BenchmarkDotNet.Attributes; | ||
using MagicOnion.Client.DynamicClient; | ||
|
||
namespace Microbenchmark.Client; | ||
|
||
[MemoryDiagnoser, RankColumn] | ||
[ShortRunJob] | ||
public class HubReceiverBroadcastBenchmarks | ||
{ | ||
StreamingHubClientTestHelper<ITestHub, ITestHubReceiver> helper = default!; | ||
ITestHub client = default!; | ||
TestHubReceiver receiver = default!; | ||
|
||
static ReadOnlySpan<byte> BroadcastMessage_Parameter_Zero => [0x92, 0xce, 0x76, 0xe4, 0x37, 0x1b /* 1994667803 */, 0xc0 /* Nil */]; // [MethodId(int), SerializedArgument] | ||
static ReadOnlySpan<byte> BroadcastMessage_Parameter_Many => [0x92, 0xce, 0x4c, 0xb8, 0x83, 0xca /* 1287160778 */, 0x93, 0xa6, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x21, 0xcd, 0x30, 0x39, 0xc3 /* [ "Hello", 12345, true ] */]; // [MethodId(int), SerializedArgument] | ||
|
||
void Setup() | ||
{ | ||
this.receiver = new TestHubReceiver(); | ||
this.helper = new StreamingHubClientTestHelper<ITestHub, ITestHubReceiver>(receiver, DynamicStreamingHubClientFactoryProvider.Instance); | ||
this.client = helper.ConnectAsync().GetAwaiter().GetResult(); | ||
} | ||
|
||
[GlobalSetup(Targets = [nameof(Parameter_Zero), nameof(Parameter_Many)])] | ||
public void UnsetSynchronizationContext() | ||
{ | ||
SynchronizationContext.SetSynchronizationContext(null); | ||
Setup(); | ||
} | ||
|
||
[GlobalSetup(Targets = [nameof(Parameter_Zero_With_SynchronizationContext), nameof(Parameter_Many_With_SynchronizationContext)])] | ||
public void SetSynchronizationContext() | ||
{ | ||
SynchronizationContext.SetSynchronizationContext(new MySynchronizationContext()); | ||
Setup(); | ||
} | ||
|
||
[Benchmark] | ||
public void Parameter_Zero() | ||
{ | ||
helper.WriteResponseRaw(BroadcastMessage_Parameter_Zero); | ||
receiver.Received.Wait(); | ||
} | ||
|
||
[Benchmark] | ||
public void Parameter_Many() | ||
{ | ||
helper.WriteResponseRaw(BroadcastMessage_Parameter_Many); | ||
receiver.Received.Wait(); | ||
} | ||
|
||
[Benchmark] | ||
public void Parameter_Zero_With_SynchronizationContext() | ||
{ | ||
helper.WriteResponseRaw(BroadcastMessage_Parameter_Zero); | ||
receiver.Received.Wait(); | ||
} | ||
|
||
[Benchmark] | ||
public void Parameter_Many_With_SynchronizationContext() | ||
{ | ||
helper.WriteResponseRaw(BroadcastMessage_Parameter_Many); | ||
receiver.Received.Wait(); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
perf/Microbenchmark/Microbenchmark.Client/Microbenchmark.Client.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
|
||
<SignAssembly>true</SignAssembly> | ||
<AssemblyOriginatorKeyFile>..\..\..\src\MagicOnion\opensource.snk</AssemblyOriginatorKeyFile> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="BenchmarkDotNet" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\..\src\MagicOnion.Client\MagicOnion.Client.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
Oops, something went wrong.