Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fd971cdecc | ||
|
|
304811c964 |
@@ -86,12 +86,14 @@ class Program
|
|||||||
DemoCheck.EventCallback = true;
|
DemoCheck.EventCallback = true;
|
||||||
};
|
};
|
||||||
Console.WriteLine("Printer created");
|
Console.WriteLine("Printer created");
|
||||||
|
Thread.Sleep(100);
|
||||||
|
|
||||||
frontendBridge.Obstacle();
|
frontendBridge.Obstacle();
|
||||||
var name = disposingPrinter.GetName();
|
var name = disposingPrinter.GetName();
|
||||||
DemoCheck.BasicNonParamsCall = true;
|
DemoCheck.BasicNonParamsCall = true;
|
||||||
Console.WriteLine("Printer name : {0}", name);
|
Console.WriteLine("Printer name : {0}", name);
|
||||||
|
|
||||||
|
Thread.Sleep(100);
|
||||||
|
|
||||||
disposingPrinter.SomeoneIsApproaching("Mikhail");
|
disposingPrinter.SomeoneIsApproaching("Mikhail");
|
||||||
Console.WriteLine("Approaching detected");
|
Console.WriteLine("Approaching detected");
|
||||||
@@ -100,14 +102,17 @@ class Program
|
|||||||
factory.Register(disposingPrinter);
|
factory.Register(disposingPrinter);
|
||||||
DemoCheck.ClientBasedImplementation = true;
|
DemoCheck.ClientBasedImplementation = true;
|
||||||
Console.WriteLine("Registered printer");
|
Console.WriteLine("Registered printer");
|
||||||
|
Thread.Sleep(100);
|
||||||
|
|
||||||
|
|
||||||
var registered = factory.GetFirstPrinter();
|
var registered = factory.GetFirstPrinter();
|
||||||
Console.WriteLine("First printer");
|
Console.WriteLine("First printer");
|
||||||
|
Thread.Sleep(100);
|
||||||
|
|
||||||
Console.WriteLine(registered);
|
Console.WriteLine(registered);
|
||||||
Console.WriteLine("Collecting all printers");
|
Console.WriteLine("Collecting all printers");
|
||||||
var names = factory.CollectAllNames();
|
var names = factory.CollectAllNames();
|
||||||
|
Thread.Sleep(100);
|
||||||
|
|
||||||
Console.WriteLine("Names: " + string.Join(", ", names));
|
Console.WriteLine("Names: " + string.Join(", ", names));
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,35 @@
|
|||||||
|
using System.Formats.Cbor;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
using mROA.Implementation;
|
||||||
|
|
||||||
|
public static class CborExtensions
|
||||||
|
{
|
||||||
|
public static unsafe void WriteToCbor(this RequestId id, CborWriter writer)
|
||||||
|
{
|
||||||
|
Span<byte> span = stackalloc byte[16];
|
||||||
|
MemoryMarshal.Write(span, ref id);
|
||||||
|
writer.WriteByteString(span);
|
||||||
|
}
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public static unsafe void WriteToCborInline(this RequestId id, CborWriter writer)
|
||||||
|
{
|
||||||
|
Span<byte> span = stackalloc byte[16];
|
||||||
|
MemoryMarshal.Write(span, ref id);
|
||||||
|
writer.WriteByteString(span);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void WriteToDest(this RequestId id, Span<byte> destination)
|
||||||
|
{
|
||||||
|
MemoryMarshal.Write(destination, ref id);
|
||||||
|
}
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveOptimization)]
|
||||||
|
public static unsafe void WriteToCborOpt(this RequestId id, CborWriter writer)
|
||||||
|
{
|
||||||
|
Span<byte> span = stackalloc byte[16];
|
||||||
|
MemoryMarshal.Write(span, ref id);
|
||||||
|
writer.WriteByteString(span);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
using BenchmarkDotNet.Attributes;
|
||||||
|
using mROA.Implementation;
|
||||||
|
|
||||||
|
namespace mROA.Benchmark;
|
||||||
|
|
||||||
|
public class IdGeneration
|
||||||
|
{
|
||||||
|
public static int X = 0;
|
||||||
|
|
||||||
|
[Benchmark]
|
||||||
|
public Guid GuidGeneration()
|
||||||
|
{
|
||||||
|
return Guid.NewGuid();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Benchmark(Baseline = true)]
|
||||||
|
public RequestId ReqIdGeneration()
|
||||||
|
{
|
||||||
|
return RequestId.Generate();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Benchmark]
|
||||||
|
public RequestId ReqIdIfGeneration()
|
||||||
|
{
|
||||||
|
var reqId = RequestId.Generate();
|
||||||
|
if (++X % 2 == 0)
|
||||||
|
{
|
||||||
|
reqId.P0 = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
reqId.P1 = 0;
|
||||||
|
}
|
||||||
|
return reqId;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,44 +1,8 @@
|
|||||||
// See https://aka.ms/new-console-template for more information
|
// See https://aka.ms/new-console-template for more information
|
||||||
|
|
||||||
using System.Formats.Cbor;
|
|
||||||
using System.Runtime.CompilerServices;
|
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
using BenchmarkDotNet.Running;
|
using BenchmarkDotNet.Running;
|
||||||
using mROA.Benchmark;
|
using mROA.Benchmark;
|
||||||
using mROA.Implementation;
|
|
||||||
|
|
||||||
Console.WriteLine("Hello, World!");
|
Console.WriteLine("Hello, World!");
|
||||||
var test = new CborTest();
|
|
||||||
test.ArrayWrite();
|
|
||||||
BenchmarkRunner.Run<VirtualOverhead>();
|
|
||||||
|
|
||||||
public static class CborExtensions
|
BenchmarkRunner.Run<IdGeneration>();
|
||||||
{
|
|
||||||
public static unsafe void WriteToCbor(this RequestId id, CborWriter writer)
|
|
||||||
{
|
|
||||||
Span<byte> span = stackalloc byte[16];
|
|
||||||
MemoryMarshal.Write(span, ref id);
|
|
||||||
writer.WriteByteString(span);
|
|
||||||
}
|
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
public static unsafe void WriteToCborInline(this RequestId id, CborWriter writer)
|
|
||||||
{
|
|
||||||
Span<byte> span = stackalloc byte[16];
|
|
||||||
MemoryMarshal.Write(span, ref id);
|
|
||||||
writer.WriteByteString(span);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void WriteToDest(this RequestId id, Span<byte> destination)
|
|
||||||
{
|
|
||||||
MemoryMarshal.Write(destination, ref id);
|
|
||||||
}
|
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveOptimization)]
|
|
||||||
public static unsafe void WriteToCborOpt(this RequestId id, CborWriter writer)
|
|
||||||
{
|
|
||||||
Span<byte> span = stackalloc byte[16];
|
|
||||||
MemoryMarshal.Write(span, ref id);
|
|
||||||
writer.WriteByteString(span);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
using System.Runtime.CompilerServices;
|
||||||
using BenchmarkDotNet.Attributes;
|
using BenchmarkDotNet.Attributes;
|
||||||
using mROA.Implementation;
|
using mROA.Implementation;
|
||||||
|
|
||||||
@@ -5,17 +6,15 @@ namespace mROA.Benchmark;
|
|||||||
|
|
||||||
public class VirtualOverhead
|
public class VirtualOverhead
|
||||||
{
|
{
|
||||||
private ICallRequest _request;
|
|
||||||
private CallRequest _directRequest;
|
private CallRequest _directRequest;
|
||||||
private RawCallRequest _rawRequest;
|
private RawCallRequest _rawRequest;
|
||||||
|
|
||||||
public VirtualOverhead()
|
[GlobalSetup]
|
||||||
{
|
public void Setup() {
|
||||||
_request = new CallRequest
|
_directRequest = new CallRequest
|
||||||
{
|
{
|
||||||
CommandId = 5, Id = new RequestId(), ObjectId = ComplexObjectIdentifier.Null, Parameters = null
|
CommandId = 5, Id = new RequestId(), ObjectId = ComplexObjectIdentifier.Null, Parameters = null
|
||||||
};
|
};
|
||||||
_directRequest = (CallRequest)_request;
|
|
||||||
_rawRequest = new RawCallRequest
|
_rawRequest = new RawCallRequest
|
||||||
{
|
{
|
||||||
CommandId = _directRequest.CommandId, Id = _directRequest.Id, ObjectId = _directRequest.ObjectId,
|
CommandId = _directRequest.CommandId, Id = _directRequest.Id, ObjectId = _directRequest.ObjectId,
|
||||||
@@ -24,18 +23,6 @@ public class VirtualOverhead
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Benchmark(Baseline = true)]
|
[Benchmark(Baseline = true)]
|
||||||
public long VirtualUsage()
|
|
||||||
{
|
|
||||||
var req = _request;
|
|
||||||
long acc = 0;
|
|
||||||
acc += req.CommandId;
|
|
||||||
acc += (long)(req.Id.P1 + req.Id.P0);
|
|
||||||
acc += req.ObjectId.ContextId + req.ObjectId.OwnerId;
|
|
||||||
acc += (req.Parameters ?? []).Length;
|
|
||||||
return acc;
|
|
||||||
}
|
|
||||||
|
|
||||||
[Benchmark]
|
|
||||||
public long DirectUsage()
|
public long DirectUsage()
|
||||||
{
|
{
|
||||||
var req = _directRequest;
|
var req = _directRequest;
|
||||||
@@ -58,6 +45,40 @@ public class VirtualOverhead
|
|||||||
acc += (req.Parameters ?? []).Length;
|
acc += (req.Parameters ?? []).Length;
|
||||||
return acc;
|
return acc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Benchmark]
|
||||||
|
public long ParamUsage()
|
||||||
|
{
|
||||||
|
return Call(_directRequest);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Benchmark]
|
||||||
|
public long ParamInUsage()
|
||||||
|
{
|
||||||
|
return CallIn(in _directRequest);
|
||||||
|
}
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||||
|
public long Call(CallRequest req)
|
||||||
|
{
|
||||||
|
long acc = 0;
|
||||||
|
acc += req.CommandId;
|
||||||
|
acc += (long)(req.Id.P1 + req.Id.P0);
|
||||||
|
acc += req.ObjectId.ContextId + req.ObjectId.OwnerId;
|
||||||
|
acc += (req.Parameters ?? []).Length;
|
||||||
|
return acc;
|
||||||
|
}
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||||
|
public long CallIn(in CallRequest req)
|
||||||
|
{
|
||||||
|
long acc = 0;
|
||||||
|
acc += req.CommandId;
|
||||||
|
acc += (long)(req.Id.P1 + req.Id.P0);
|
||||||
|
acc += req.ObjectId.ContextId + req.ObjectId.OwnerId;
|
||||||
|
acc += (req.Parameters ?? []).Length;
|
||||||
|
return acc;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public struct RawCallRequest
|
public struct RawCallRequest
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ namespace mROA.Cbor
|
|||||||
{
|
{
|
||||||
public class CborSerializationToolkit : IContextualSerializationToolKit
|
public class CborSerializationToolkit : IContextualSerializationToolKit
|
||||||
{
|
{
|
||||||
private readonly CborWriter _writer = new(initialCapacity: 512);
|
private readonly CborWriter _writer = new(initialCapacity: 2048);
|
||||||
|
|
||||||
private readonly IOrdinaryStructureParser[] _parsers =
|
private readonly IOrdinaryStructureParser[] _parsers =
|
||||||
{
|
{
|
||||||
@@ -118,6 +118,11 @@ namespace mROA.Cbor
|
|||||||
return Convert.ChangeType(nonCasted, type);
|
return Convert.ChangeType(nonCasted, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IContextualSerializationToolKit Clone()
|
||||||
|
{
|
||||||
|
return new CborSerializationToolkit();
|
||||||
|
}
|
||||||
|
|
||||||
public void WriteData(object? obj, CborWriter writer, IEndPointContext? context)
|
public void WriteData(object? obj, CborWriter writer, IEndPointContext? context)
|
||||||
{
|
{
|
||||||
if (obj is not null && FindParser(obj.GetType(), out var parser))
|
if (obj is not null && FindParser(obj.GetType(), out var parser))
|
||||||
|
|||||||
@@ -10,5 +10,6 @@ namespace mROA.Abstract
|
|||||||
object? Deserialize(byte[] rawData, Type type, IEndPointContext? context);
|
object? Deserialize(byte[] rawData, Type type, IEndPointContext? context);
|
||||||
T Deserialize<T>(ReadOnlyMemory<byte> rawMemory, IEndPointContext? context);
|
T Deserialize<T>(ReadOnlyMemory<byte> rawMemory, IEndPointContext? context);
|
||||||
object? Cast(object? nonCasted, Type type, IEndPointContext? context);
|
object? Cast(object? nonCasted, Type type, IEndPointContext? context);
|
||||||
|
IContextualSerializationToolKit Clone();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -25,15 +25,15 @@ namespace mROA.Implementation.Backend
|
|||||||
|
|
||||||
public IRequestExtractor this[int id] => _producedExtractors[id];
|
public IRequestExtractor this[int id] => _producedExtractors[id];
|
||||||
|
|
||||||
public IRequestExtractor HubOnOnConnected(IRepresentationModule interaction)
|
public IRequestExtractor HubOnOnConnected(IRepresentationModule representationModule)
|
||||||
{
|
{
|
||||||
var extractor = CreateExtractor(interaction);
|
var extractor = CreateExtractor(representationModule);
|
||||||
if (_mode.DistributionType == EDistributionType.Channeled)
|
if (_mode.DistributionType == EDistributionType.Channeled)
|
||||||
{
|
{
|
||||||
extractor.StartExtraction().ContinueWith(_ => OnDisconnected(interaction));
|
extractor.StartExtraction().ContinueWith(_ => OnDisconnected(representationModule));
|
||||||
}
|
}
|
||||||
|
|
||||||
_producedExtractors[interaction.Id] = extractor;
|
_producedExtractors[representationModule.Id] = extractor;
|
||||||
return extractor;
|
return extractor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ namespace mROA.Implementation.Backend
|
|||||||
_extractorsTokenSources[interaction.ConnectionId] = cts;
|
_extractorsTokenSources[interaction.ConnectionId] = cts;
|
||||||
|
|
||||||
_hub.RegisterInteraction(interaction);
|
_hub.RegisterInteraction(interaction);
|
||||||
var requestExtractor = _hre.HubOnOnConnected(new RepresentationModule(interaction, _serialization));
|
var requestExtractor = _hre.HubOnOnConnected(new RepresentationModule(interaction, _serialization.Clone()));
|
||||||
|
|
||||||
if (_distribution.DistributionType != EDistributionType.Channeled)
|
if (_distribution.DistributionType != EDistributionType.Channeled)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -170,9 +170,6 @@ namespace mROA.Implementation
|
|||||||
}
|
}
|
||||||
|
|
||||||
var message = meta.ToMessage(_buffer.Span);
|
var message = meta.ToMessage(_buffer.Span);
|
||||||
#if TRACE
|
|
||||||
Console.WriteLine("RECV " + message);
|
|
||||||
#endif
|
|
||||||
MessageReceived(message);
|
MessageReceived(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -191,9 +188,6 @@ namespace mROA.Implementation
|
|||||||
message.Data.CopyTo(_buffer.Span[19..]);
|
message.Data.CopyTo(_buffer.Span[19..]);
|
||||||
var sendingSpan = _buffer[..(19 + meta.BodyLength)];
|
var sendingSpan = _buffer[..(19 + meta.BodyLength)];
|
||||||
await _ioStream.WriteAsync(sendingSpan, token);
|
await _ioStream.WriteAsync(sendingSpan, token);
|
||||||
#if TRACE
|
|
||||||
Console.WriteLine("SEND " + message);
|
|
||||||
#endif
|
|
||||||
// _logger.LogTrace("SEND {0}", message.ToString());
|
// _logger.LogTrace("SEND {0}", message.ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,12 +13,11 @@ namespace mROA.Implementation
|
|||||||
_serialization = serialization;
|
_serialization = serialization;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public IRepresentationModule Produce(int id)
|
public IRepresentationModule Produce(int id)
|
||||||
{
|
{
|
||||||
var interaction = _hub.GetInteraction(id);
|
var interaction = _hub.GetInteraction(id);
|
||||||
|
|
||||||
var produced = new RepresentationModule(interaction, _serialization);
|
var produced = new RepresentationModule(interaction, _serialization.Clone());
|
||||||
|
|
||||||
return produced;
|
return produced;
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -22,7 +22,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
|
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
|
||||||
<DefineConstants>;</DefineConstants>
|
<DefineConstants></DefineConstants>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
Reference in New Issue
Block a user