Benchmark kaput

This commit is contained in:
2025-08-16 12:14:03 +03:00
parent 8c137115f4
commit 24d346795d
9 changed files with 219 additions and 21 deletions
+5 -2
View File
@@ -22,12 +22,12 @@ class Program
builder.Services.AddSingleton<IGatewayModule, NetworkGatewayModule>(); builder.Services.AddSingleton<IGatewayModule, NetworkGatewayModule>();
builder.Services.AddSingleton<IUntrustedGateway, UdpGateway>(); builder.Services.AddSingleton<IUntrustedGateway, UdpGateway>();
builder.Services.AddSingleton<IConnectionHub, ConnectionHub>(); builder.Services.AddSingleton<IConnectionHub, ConnectionHub>();
builder.Services.AddOptions(); builder.Services.AddOptions();
var listening = new IPEndPoint(IPAddress.Any, 4567); var listening = new IPEndPoint(IPAddress.Any, 4567);
builder.Services.Configure<GatewayOptions>(options => options.Endpoint = listening); builder.Services.Configure<GatewayOptions>(options => options.Endpoint = listening);
builder.Services.AddSingleton<IDistributionModule, ExtractorFirstDistributionModule>(); builder.Services.AddSingleton<IDistributionModule, ExtractorFirstDistributionModule>();
builder.Services.AddSingleton<HubRequestExtractor>(); builder.Services.AddSingleton<HubRequestExtractor>();
builder.Services.AddSingleton<IExecuteModule, BasicExecutionModule>(); builder.Services.AddSingleton<IExecuteModule, BasicExecutionModule>();
builder.Services.AddSingleton<IRepresentationModuleProducer, CreativeRepresentationModuleProducer>(); builder.Services.AddSingleton<IRepresentationModuleProducer, CreativeRepresentationModuleProducer>();
@@ -55,6 +55,9 @@ class Program
// //
new RemoteTypeBinder(); new RemoteTypeBinder();
// //
var contextualSerializationToolKit = host.Services.GetService<IContextualSerializationToolKit>();
contextualSerializationToolKit.Deserialize<NetworkMessage>(contextualSerializationToolKit.Serialize(new NetworkMessage(), null), null);
_ = host.Services.GetService<IUntrustedGateway>()!.Start(); _ = host.Services.GetService<IUntrustedGateway>()!.Start();
var gateway = host.Services.GetService<IGatewayModule>(); var gateway = host.Services.GetService<IGatewayModule>();
gateway.Run(); gateway.Run();
+110
View File
@@ -0,0 +1,110 @@
using BenchmarkDotNet.Attributes;
using mROA.Abstract;
using mROA.Codegen;
using mROA.Implementation;
namespace mROA.Benchmark;
[MemoryDiagnoser]
[DisassemblyDiagnoser]
public class MethodAccess
{
private CollectableMethodRepository _current = new();
private FastMethodRepository _fast = new();
private readonly int _count = new GeneratedInvokersCollection().Count;
[GlobalSetup]
public void SetupMethodAccess()
{
_current.AppendInvokers(new GeneratedInvokersCollection());
_fast.AppendInvokers(new GeneratedInvokersCollection());
}
// [Benchmark(Baseline = true)]
// public IMethodInvoker CurrentSingle()
// {
// return _current.GetMethod(0);
// }
//
// [Benchmark]
// public IMethodInvoker CurrentDispose()
// {
// return _current.GetMethod(-1);
// }
//
// [Benchmark]
// public IMethodInvoker FastSingle()
// {
// return _fast.GetMethod(0);
// }
//
// [Benchmark]
// public IMethodInvoker FastDispose()
// {
// return _fast.GetMethod(-1);
// }
// [Benchmark]
// public IMethodInvoker FastSingleBaked()
// {
// return _fast.GetMethodBaked(0);
// }
//
// [Benchmark]
// public IMethodInvoker FastDisposeBaked()
// {
// return _fast.GetMethodBaked(-1);
// }
[Benchmark(Baseline = true)]
public IMethodInvoker CurrentAll()
{
IMethodInvoker inv = null;
for (int i = -1; i < _count; i++)
{
inv = _current.GetMethod(i);
}
return inv;
}
[Benchmark]
public IMethodInvoker FastAll()
{
IMethodInvoker inv = null;
for (int i = -1; i < _count; i++)
{
inv = _fast.GetMethod(i);
}
return inv;
}
[Benchmark]
public IMethodInvoker FastAllBaked()
{
IMethodInvoker inv = null;
for (int i = -1; i < _count; i++)
{
inv = _fast.GetMethodBaked(i);
}
return inv;
}
}
internal class FastMethodRepository: IMethodRepository
{
private readonly List<IMethodInvoker> _methods = [MethodInvoker.Dispose];
private IMethodInvoker[] _baked = [];
public void AppendInvokers(IEnumerable<IMethodInvoker> methodInvokers)
{
_methods.AddRange(methodInvokers);
_baked = _methods.ToArray();
}
public IMethodInvoker GetMethod(int id)
{
return _methods[id + 1];
}
public IMethodInvoker GetMethodBaked(int id)
{
return _baked[id + 1];
}
}
+2 -2
View File
@@ -3,6 +3,6 @@
using BenchmarkDotNet.Running; using BenchmarkDotNet.Running;
using mROA.Benchmark; using mROA.Benchmark;
Console.WriteLine("Hello, World!"); Console.WriteLine("Hello, Performance!");
BenchmarkRunner.Run<InvokePerformance>(); BenchmarkRunner.Run<MethodAccess>();
+73
View File
@@ -0,0 +1,73 @@
using BenchmarkDotNet.Attributes;
using mROA.Implementation;
namespace mROA.Benchmark;
public class StackOperations
{
private Stack<StackFrame> stack = new();
public StackOperations()
{
}
[Benchmark]
public void Stack()
{
}
private readonly struct StackFrame
{
public StackFrame(
CborMajorType? type,
int frameOffset,
int? definiteLength,
int itemsWritten,
int? currentKeyOffset,
int? currentValueOffset,
List<int>? keyValuePairEncodingRanges,
HashSet<(int Offset, int Length)>? keyEncodingRanges)
{
MajorType = type;
FrameOffset = frameOffset;
DefiniteLength = definiteLength;
ItemsWritten = itemsWritten;
CurrentKeyOffset = currentKeyOffset;
CurrentValueOffset = currentValueOffset;
KeyValuePairEncodingRanges = keyValuePairEncodingRanges;
KeyEncodingRanges = keyEncodingRanges;
}
public CborMajorType? MajorType { get; }
public int FrameOffset { get; }
public int? DefiniteLength { get; }
public int ItemsWritten { get; }
public int? CurrentKeyOffset { get; }
public int? CurrentValueOffset { get; }
public List<int>? KeyValuePairEncodingRanges { get; }
public HashSet<(int Offset, int Length)>? KeyEncodingRanges { get; }
}
}
internal enum CborMajorType
{
Unknown,
Int8,
Int16,
Int32,
Int64,
UInt8,
UInt16,
UInt32,
UInt64,
Float32,
Float64,
Double,
Double2,
Double3,
}
+1
View File
@@ -9,6 +9,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Example.Shared\Example.Shared.csproj" />
<ProjectReference Include="..\mROA.Cbor\mROA.Cbor.csproj" /> <ProjectReference Include="..\mROA.Cbor\mROA.Cbor.csproj" />
<ProjectReference Include="..\mROA\mROA.csproj" /> <ProjectReference Include="..\mROA\mROA.csproj" />
</ItemGroup> </ItemGroup>
+25 -5
View File
@@ -58,7 +58,7 @@ namespace mROA.Cbor
WriteData(objectToSerialize, _writer, context); WriteData(objectToSerialize, _writer, context);
result = _writer.Encode(); result = _writer.Encode();
} }
return result; return result;
} }
@@ -99,7 +99,6 @@ namespace mROA.Cbor
Console.WriteLine($"Bad deserialization. Bytes: {rawMemory.ToArray().Select(b => $"{b:X}")}"); Console.WriteLine($"Bad deserialization. Bytes: {rawMemory.ToArray().Select(b => $"{b:X}")}");
throw; throw;
} }
} }
public T Cast<T>(object nonCasted, IEndPointContext? context) public T Cast<T>(object nonCasted, IEndPointContext? context)
@@ -128,7 +127,7 @@ namespace mROA.Cbor
{ {
return ReadSharedShell(type, context, (ulong)nonCasted); return ReadSharedShell(type, context, (ulong)nonCasted);
} }
return Convert.ChangeType(nonCasted, type); return Convert.ChangeType(nonCasted, type);
} }
@@ -196,9 +195,20 @@ namespace mROA.Cbor
WriteObject(sharedObject, writer, context); WriteObject(sharedObject, writer, context);
break; break;
default: default:
if (obj.GetType().IsEnum) var objType = obj.GetType();
if (objType.IsEnum)
{ {
writer.WriteInt32((int)obj); var basicType = Enum.GetUnderlyingType(obj.GetType());
if (basicType == typeof(byte))
{
writer.WriteInt32((byte)obj);
}
else if (basicType == typeof(int))
{
writer.WriteInt32((byte)obj);
}
break; break;
} }
@@ -283,6 +293,7 @@ namespace mROA.Cbor
{ {
return ReadSharedShell(type, context, reader.ReadUInt64()); return ReadSharedShell(type, context, reader.ReadUInt64());
} }
return reader.ReadUInt64(); return reader.ReadUInt64();
case CborReaderState.ByteString: case CborReaderState.ByteString:
if (type == typeof(RequestId)) if (type == typeof(RequestId))
@@ -446,6 +457,15 @@ namespace mROA.Cbor
{ {
var property = properties[index]; var property = properties[index];
var value = ReadData(reader, property.PropertyType, context); var value = ReadData(reader, property.PropertyType, context);
if (property.PropertyType.IsEnum)
{
if (property.PropertyType.GetEnumUnderlyingType() == typeof(byte))
{
value = Convert.ChangeType(value, typeof(byte));
}
}
property.SetValue(obj, value); property.SetValue(obj, value);
} }
+2 -2
View File
@@ -4,7 +4,7 @@
<TargetFramework>netstandard2.1</TargetFramework> <TargetFramework>netstandard2.1</TargetFramework>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild> <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>2.0.7</Version> <Version>3.0.3</Version>
<LangVersion>9</LangVersion> <LangVersion>9</LangVersion>
<PackageIcon>mroaLogo.png</PackageIcon> <PackageIcon>mroaLogo.png</PackageIcon>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
@@ -31,6 +31,6 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="System.Formats.Cbor" Version="9.0.7" /> <PackageReference Include="System.Formats.Cbor" Version="9.0.8" />
</ItemGroup> </ItemGroup>
</Project> </Project>
-2
View File
@@ -35,8 +35,6 @@ namespace mROA.Implementation
public EMessageType MessageType { get; set; } public EMessageType MessageType { get; set; }
public byte[] Data { get; set; } public byte[] Data { get; set; }
public object Serialized { get; set; }
public IEndPointContext Context { get; set; }
public override string ToString() public override string ToString()
{ {
+1 -8
View File
@@ -4,7 +4,7 @@
<TargetFramework>netstandard2.1</TargetFramework> <TargetFramework>netstandard2.1</TargetFramework>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<Title>mROA</Title> <Title>mROA</Title>
<Version>2.0.8</Version> <Version>3.0.3</Version>
<Authors>YaslePoy</Authors> <Authors>YaslePoy</Authors>
<Description>Fast and easy RPC with contex</Description> <Description>Fast and easy RPC with contex</Description>
<RepositoryUrl>https://github.com/YaslePoy/mROA</RepositoryUrl> <RepositoryUrl>https://github.com/YaslePoy/mROA</RepositoryUrl>
@@ -38,11 +38,4 @@
<PackagePath></PackagePath> <PackagePath></PackagePath>
</None> </None>
</ItemGroup> </ItemGroup>
<ItemGroup>
<Reference Include="Microsoft.Extensions.Logging.Abstractions">
<HintPath>..\..\..\..\.nuget\packages\microsoft.extensions.logging.abstractions\9.0.7\lib\netstandard2.0\Microsoft.Extensions.Logging.Abstractions.dll</HintPath>
</Reference>
</ItemGroup>
</Project> </Project>