2 Commits
Author SHA1 Message Date
micialware 37e768d6e8 Remove waiting from demo 2025-08-06 15:03:46 +03:00
micialware 5ece345a3f Add logging 2025-08-06 14:50:10 +03:00
12 changed files with 70 additions and 131 deletions
-5
View File
@@ -86,14 +86,12 @@ class Program
DemoCheck.EventCallback = true;
};
Console.WriteLine("Printer created");
Thread.Sleep(100);
frontendBridge.Obstacle();
var name = disposingPrinter.GetName();
DemoCheck.BasicNonParamsCall = true;
Console.WriteLine("Printer name : {0}", name);
Thread.Sleep(100);
disposingPrinter.SomeoneIsApproaching("Mikhail");
Console.WriteLine("Approaching detected");
@@ -102,17 +100,14 @@ class Program
factory.Register(disposingPrinter);
DemoCheck.ClientBasedImplementation = true;
Console.WriteLine("Registered printer");
Thread.Sleep(100);
var registered = factory.GetFirstPrinter();
Console.WriteLine("First printer");
Thread.Sleep(100);
Console.WriteLine(registered);
Console.WriteLine("Collecting all printers");
var names = factory.CollectAllNames();
Thread.Sleep(100);
Console.WriteLine("Names: " + string.Join(", ", names));
-35
View File
@@ -1,35 +0,0 @@
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);
}
}
-37
View File
@@ -1,37 +0,0 @@
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;
}
}
+37 -1
View File
@@ -1,8 +1,44 @@
// 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 mROA.Benchmark;
using mROA.Implementation;
Console.WriteLine("Hello, World!");
var test = new CborTest();
test.ArrayWrite();
BenchmarkRunner.Run<VirtualOverhead>();
BenchmarkRunner.Run<IdGeneration>();
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);
}
}
+18 -39
View File
@@ -1,4 +1,3 @@
using System.Runtime.CompilerServices;
using BenchmarkDotNet.Attributes;
using mROA.Implementation;
@@ -6,15 +5,17 @@ namespace mROA.Benchmark;
public class VirtualOverhead
{
private ICallRequest _request;
private CallRequest _directRequest;
private RawCallRequest _rawRequest;
[GlobalSetup]
public void Setup() {
_directRequest = new CallRequest
public VirtualOverhead()
{
_request = new CallRequest
{
CommandId = 5, Id = new RequestId(), ObjectId = ComplexObjectIdentifier.Null, Parameters = null
};
_directRequest = (CallRequest)_request;
_rawRequest = new RawCallRequest
{
CommandId = _directRequest.CommandId, Id = _directRequest.Id, ObjectId = _directRequest.ObjectId,
@@ -23,6 +24,18 @@ public class VirtualOverhead
}
[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()
{
var req = _directRequest;
@@ -45,40 +58,6 @@ public class VirtualOverhead
acc += (req.Parameters ?? []).Length;
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
+1 -6
View File
@@ -14,7 +14,7 @@ namespace mROA.Cbor
{
public class CborSerializationToolkit : IContextualSerializationToolKit
{
private readonly CborWriter _writer = new(initialCapacity: 2048);
private readonly CborWriter _writer = new(initialCapacity: 512);
private readonly IOrdinaryStructureParser[] _parsers =
{
@@ -118,11 +118,6 @@ namespace mROA.Cbor
return Convert.ChangeType(nonCasted, type);
}
public IContextualSerializationToolKit Clone()
{
return new CborSerializationToolkit();
}
public void WriteData(object? obj, CborWriter writer, IEndPointContext? context)
{
if (obj is not null && FindParser(obj.GetType(), out var parser))
@@ -10,6 +10,5 @@ namespace mROA.Abstract
object? Deserialize(byte[] rawData, Type type, IEndPointContext? context);
T Deserialize<T>(ReadOnlyMemory<byte> rawMemory, 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 HubOnOnConnected(IRepresentationModule representationModule)
public IRequestExtractor HubOnOnConnected(IRepresentationModule interaction)
{
var extractor = CreateExtractor(representationModule);
var extractor = CreateExtractor(interaction);
if (_mode.DistributionType == EDistributionType.Channeled)
{
extractor.StartExtraction().ContinueWith(_ => OnDisconnected(representationModule));
extractor.StartExtraction().ContinueWith(_ => OnDisconnected(interaction));
}
_producedExtractors[representationModule.Id] = extractor;
_producedExtractors[interaction.Id] = extractor;
return extractor;
}
@@ -106,7 +106,7 @@ namespace mROA.Implementation.Backend
_extractorsTokenSources[interaction.ConnectionId] = cts;
_hub.RegisterInteraction(interaction);
var requestExtractor = _hre.HubOnOnConnected(new RepresentationModule(interaction, _serialization.Clone()));
var requestExtractor = _hre.HubOnOnConnected(new RepresentationModule(interaction, _serialization));
if (_distribution.DistributionType != EDistributionType.Channeled)
{
@@ -170,6 +170,9 @@ namespace mROA.Implementation
}
var message = meta.ToMessage(_buffer.Span);
#if TRACE
Console.WriteLine("RECV " + message);
#endif
MessageReceived(message);
}
@@ -188,6 +191,9 @@ namespace mROA.Implementation
message.Data.CopyTo(_buffer.Span[19..]);
var sendingSpan = _buffer[..(19 + meta.BodyLength)];
await _ioStream.WriteAsync(sendingSpan, token);
#if TRACE
Console.WriteLine("SEND " + message);
#endif
// _logger.LogTrace("SEND {0}", message.ToString());
}
@@ -13,11 +13,12 @@ namespace mROA.Implementation
_serialization = serialization;
}
public IRepresentationModule Produce(int id)
{
var interaction = _hub.GetInteraction(id);
var produced = new RepresentationModule(interaction, _serialization.Clone());
var produced = new RepresentationModule(interaction, _serialization);
return produced;
}
+1 -1
View File
@@ -22,7 +22,7 @@
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<DefineConstants></DefineConstants>
<DefineConstants>;</DefineConstants>
</PropertyGroup>
<ItemGroup>