mirror of
https://github.com/FabInfra/capnproto-dotnetcore_Runtime.git
synced 2025-03-12 06:41:50 +01:00
performance optimizations
This commit is contained in:
parent
47cb578057
commit
5e71ce69c5
@ -7,7 +7,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="BenchmarkDotNet" Version="0.12.0" />
|
||||
<PackageReference Include="Capnp.Net.Runtime" Version="1.2.189" />
|
||||
<PackageReference Include="Capnp.Net.Runtime" Version="1.3.22-g47cb578057" />
|
||||
<PackageReference Include="CapnpC.CSharp.MsBuild.Generation" Version="1.2.138" />
|
||||
<PackageReference Include="Google.Protobuf" Version="3.11.3" />
|
||||
<PackageReference Include="Grpc.Net.Client" Version="2.27.0" />
|
||||
|
25
Benchmarking/CapnpProfile.sln
Normal file
25
Benchmarking/CapnpProfile.sln
Normal file
@ -0,0 +1,25 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 16
|
||||
VisualStudioVersion = 16.0.29728.190
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CapnpProfile", "CapnpProfile\CapnpProfile.csproj", "{D2D3AE23-C19E-47C7-B758-E2259DC01B5A}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{D2D3AE23-C19E-47C7-B758-E2259DC01B5A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{D2D3AE23-C19E-47C7-B758-E2259DC01B5A}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{D2D3AE23-C19E-47C7-B758-E2259DC01B5A}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{D2D3AE23-C19E-47C7-B758-E2259DC01B5A}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {F5DDDA09-394B-4A71-B6BE-C7103BCEF3A2}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
13
Benchmarking/CapnpProfile/CapnpProfile.csproj
Normal file
13
Benchmarking/CapnpProfile/CapnpProfile.csproj
Normal file
@ -0,0 +1,13 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Capnp.Net.Runtime" Version="1.3.22-g47cb578057" />
|
||||
<PackageReference Include="CapnpC.CSharp.MsBuild.Generation" Version="1.3.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
30
Benchmarking/CapnpProfile/Program.cs
Normal file
30
Benchmarking/CapnpProfile/Program.cs
Normal file
@ -0,0 +1,30 @@
|
||||
using Capnp.Rpc;
|
||||
using CapnpGen;
|
||||
using CapnpProfile.Services;
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CapnpProfile
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static async Task Main(string[] args)
|
||||
{
|
||||
using var server = new TcpRpcServer(IPAddress.Any, 5002);
|
||||
server.Main = new CapnpEchoService();
|
||||
using var client = new TcpRpcClient("localhost", 5002);
|
||||
await client.WhenConnected;
|
||||
using var echoer = client.GetMain<IEchoer>();
|
||||
var payload = new byte[200000];
|
||||
new Random().NextBytes(payload);
|
||||
|
||||
while (true)
|
||||
{
|
||||
var result = await echoer.Echo(payload);
|
||||
if (result.Count != payload.Length)
|
||||
throw new InvalidOperationException("Echo server malfunction");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
5
Benchmarking/CapnpProfile/Protos/Echo.capnp
Normal file
5
Benchmarking/CapnpProfile/Protos/Echo.capnp
Normal file
@ -0,0 +1,5 @@
|
||||
@0x8c309c720de8cf7c;
|
||||
|
||||
interface Echoer {
|
||||
echo @0 (input : Data) -> (output : Data);
|
||||
}
|
20
Benchmarking/CapnpProfile/Services/CapnpEchoService.cs
Normal file
20
Benchmarking/CapnpProfile/Services/CapnpEchoService.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CapnpProfile.Services
|
||||
{
|
||||
public class CapnpEchoService : CapnpGen.IEchoer
|
||||
{
|
||||
public void Dispose()
|
||||
{
|
||||
}
|
||||
|
||||
public Task<IReadOnlyList<byte>> Echo(IReadOnlyList<byte> input, CancellationToken cancellationToken_ = default)
|
||||
{
|
||||
return Task.FromResult(input);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
@ -6,7 +6,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Capnp.Net.Runtime" Version="1.2.189" />
|
||||
<PackageReference Include="Capnp.Net.Runtime" Version="1.3.22-g47cb578057" />
|
||||
<PackageReference Include="CapnpC.CSharp.MsBuild.Generation" Version="1.2.138" />
|
||||
</ItemGroup>
|
||||
|
||||
|
10
Benchmarking/nuget.config
Normal file
10
Benchmarking/nuget.config
Normal file
@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<config>
|
||||
<add key="repositoryPath" value="..\packages" />
|
||||
<add key="globalPackagesFolder" value="..\globalPackages" />
|
||||
</config>
|
||||
<packageSources>
|
||||
<add key="CapnpRuntimeSource" value="..\GeneratedNuGetPackages\Release" />
|
||||
</packageSources>
|
||||
</configuration>
|
@ -516,28 +516,28 @@ namespace Capnp
|
||||
switch (Kind)
|
||||
{
|
||||
case ObjectKind.ListOfBits:
|
||||
return new ListOfBitsDeserializer(ref this, false);
|
||||
return new ListOfBitsDeserializer(this, false);
|
||||
|
||||
case ObjectKind.ListOfBytes:
|
||||
return new ListOfPrimitivesDeserializer<byte>(ref this, ListKind.ListOfBytes);
|
||||
return new ListOfPrimitivesDeserializer<byte>(this, ListKind.ListOfBytes);
|
||||
|
||||
case ObjectKind.ListOfEmpty:
|
||||
return new ListOfEmptyDeserializer(ref this);
|
||||
return new ListOfEmptyDeserializer(this);
|
||||
|
||||
case ObjectKind.ListOfInts:
|
||||
return new ListOfPrimitivesDeserializer<int>(ref this, ListKind.ListOfInts);
|
||||
return new ListOfPrimitivesDeserializer<int>(this, ListKind.ListOfInts);
|
||||
|
||||
case ObjectKind.ListOfLongs:
|
||||
return new ListOfPrimitivesDeserializer<long>(ref this, ListKind.ListOfLongs);
|
||||
return new ListOfPrimitivesDeserializer<long>(this, ListKind.ListOfLongs);
|
||||
|
||||
case ObjectKind.ListOfPointers:
|
||||
return new ListOfPointersDeserializer(ref this);
|
||||
return new ListOfPointersDeserializer(this);
|
||||
|
||||
case ObjectKind.ListOfShorts:
|
||||
return new ListOfPrimitivesDeserializer<short>(ref this, ListKind.ListOfShorts);
|
||||
return new ListOfPrimitivesDeserializer<short>(this, ListKind.ListOfShorts);
|
||||
|
||||
case ObjectKind.ListOfStructs:
|
||||
return new ListOfStructsDeserializer(ref this);
|
||||
return new ListOfStructsDeserializer(this);
|
||||
|
||||
case ObjectKind.Nil:
|
||||
return new EmptyListDeserializer();
|
||||
@ -557,7 +557,7 @@ namespace Capnp
|
||||
switch (Kind)
|
||||
{
|
||||
case ObjectKind.ListOfPointers:
|
||||
return new ListOfCapsDeserializer<T>(ref this);
|
||||
return new ListOfCapsDeserializer<T>(this);
|
||||
|
||||
default:
|
||||
throw new DeserializationException("Cannot deserialize this object as capability list");
|
||||
|
@ -34,7 +34,7 @@ namespace Capnp
|
||||
/// </summary>
|
||||
protected readonly DeserializerState State;
|
||||
|
||||
internal ListDeserializer(ref DeserializerState state)
|
||||
internal ListDeserializer(in DeserializerState state)
|
||||
{
|
||||
State = state;
|
||||
}
|
||||
|
@ -11,8 +11,8 @@ namespace Capnp
|
||||
{
|
||||
readonly bool _defaultValue;
|
||||
|
||||
internal ListOfBitsDeserializer(ref DeserializerState context, bool defaultValue) :
|
||||
base(ref context)
|
||||
internal ListOfBitsDeserializer(in DeserializerState context, bool defaultValue) :
|
||||
base(context)
|
||||
{
|
||||
_defaultValue = defaultValue;
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ namespace Capnp
|
||||
public class ListOfCapsDeserializer<T> : ListDeserializer, IReadOnlyList<T>
|
||||
where T: class
|
||||
{
|
||||
internal ListOfCapsDeserializer(ref DeserializerState state) : base(ref state)
|
||||
internal ListOfCapsDeserializer(in DeserializerState state) : base(state)
|
||||
{
|
||||
Rpc.CapabilityReflection.ValidateCapabilityInterface(typeof(T));
|
||||
}
|
||||
|
@ -10,8 +10,8 @@ namespace Capnp
|
||||
/// </summary>
|
||||
public class ListOfEmptyDeserializer : ListDeserializer, IReadOnlyList<DeserializerState>
|
||||
{
|
||||
internal ListOfEmptyDeserializer(ref DeserializerState state) :
|
||||
base(ref state)
|
||||
internal ListOfEmptyDeserializer(in DeserializerState state) :
|
||||
base(state)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -9,8 +9,8 @@ namespace Capnp
|
||||
/// </summary>
|
||||
public class ListOfPointersDeserializer: ListDeserializer, IReadOnlyList<DeserializerState>
|
||||
{
|
||||
internal ListOfPointersDeserializer(ref DeserializerState state) :
|
||||
base(ref state)
|
||||
internal ListOfPointersDeserializer(in DeserializerState state) :
|
||||
base(state)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -11,7 +11,7 @@ namespace Capnp
|
||||
/// </summary>
|
||||
/// <typeparam name="T">List element type</typeparam>
|
||||
public class ListOfPrimitivesDeserializer<T>: ListDeserializer, IReadOnlyList<T>
|
||||
where T: struct
|
||||
where T: unmanaged
|
||||
{
|
||||
class ListOfULongAsStructView<U> : IReadOnlyList<U>
|
||||
{
|
||||
@ -73,12 +73,10 @@ namespace Capnp
|
||||
|
||||
readonly ListKind _kind;
|
||||
|
||||
internal ListOfPrimitivesDeserializer(ref DeserializerState state, ListKind kind) :
|
||||
base(ref state)
|
||||
internal ListOfPrimitivesDeserializer(in DeserializerState state, ListKind kind) :
|
||||
base(state)
|
||||
{
|
||||
_kind = kind;
|
||||
|
||||
var binCoder = PrimitiveCoder.Get<T>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -96,13 +94,12 @@ namespace Capnp
|
||||
/// <exception cref="IndexOutOfRangeException"><paramref name="index"/> is out of range.</exception>
|
||||
public T this[int index] => Data[index];
|
||||
|
||||
ListOfPrimitivesDeserializer<U> PrimitiveCast<U>() where U: struct
|
||||
ListOfPrimitivesDeserializer<U> PrimitiveCast<U>() where U: unmanaged
|
||||
{
|
||||
if (Marshal.SizeOf<U>() != Marshal.SizeOf<T>())
|
||||
throw new NotSupportedException("Source and target types have different sizes, cannot cast");
|
||||
|
||||
var stateCopy = State;
|
||||
return new ListOfPrimitivesDeserializer<U>(ref stateCopy, Kind);
|
||||
return new ListOfPrimitivesDeserializer<U>(State, Kind);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -9,8 +9,8 @@ namespace Capnp
|
||||
/// </summary>
|
||||
public class ListOfStructsDeserializer: ListDeserializer, IReadOnlyList<DeserializerState>
|
||||
{
|
||||
internal ListOfStructsDeserializer(ref DeserializerState context):
|
||||
base(ref context)
|
||||
internal ListOfStructsDeserializer(in DeserializerState context):
|
||||
base(context)
|
||||
{
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user