Faster codegen
This commit is contained in:
@@ -14,7 +14,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
|
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
|
||||||
<DefineConstants></DefineConstants>
|
<DefineConstants>JUST_LOAD</DefineConstants>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -131,7 +131,7 @@ class Program
|
|||||||
DemoCheck.TaskCancelation = true;
|
DemoCheck.TaskCancelation = true;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
const int iterations = 10;
|
const int iterations = 10000;
|
||||||
var timer = Stopwatch.StartNew();
|
var timer = Stopwatch.StartNew();
|
||||||
var x = 0;
|
var x = 0;
|
||||||
for (int i = 0; i < iterations; i++)
|
for (int i = 0; i < iterations; i++)
|
||||||
@@ -147,7 +147,6 @@ class Program
|
|||||||
|
|
||||||
frontendBridge.Disconnect();
|
frontendBridge.Disconnect();
|
||||||
|
|
||||||
DemoCheck.Show();
|
// DemoCheck.Show();
|
||||||
Console.ReadKey();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -13,6 +13,7 @@ namespace mROA.Cbor
|
|||||||
{
|
{
|
||||||
public class CborSerializationToolkit : IContextualSerializationToolKit
|
public class CborSerializationToolkit : IContextualSerializationToolKit
|
||||||
{
|
{
|
||||||
|
private static Dictionary<Type, List<PropertyInfo>> _propertiesCache = new();
|
||||||
public static TimeSpan SerializationTime = TimeSpan.Zero;
|
public static TimeSpan SerializationTime = TimeSpan.Zero;
|
||||||
public byte[] Serialize(object objectToSerialize, IEndPointContext context)
|
public byte[] Serialize(object objectToSerialize, IEndPointContext context)
|
||||||
{
|
{
|
||||||
@@ -231,7 +232,7 @@ namespace mROA.Cbor
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var properties = FilterProperties(type.GetProperties());
|
var properties = GetAvalibleProperties(type);
|
||||||
var values = properties.Select(property => property.GetValue(obj)).ToList();
|
var values = properties.Select(property => property.GetValue(obj)).ToList();
|
||||||
WriteList(values, writer, context);
|
WriteList(values, writer, context);
|
||||||
}
|
}
|
||||||
@@ -402,9 +403,7 @@ namespace mROA.Cbor
|
|||||||
|
|
||||||
private void FillObject(object obj, Type type, CborReader reader, IEndPointContext? context)
|
private void FillObject(object obj, Type type, CborReader reader, IEndPointContext? context)
|
||||||
{
|
{
|
||||||
var propertyInfos = type.GetProperties();
|
var properties = GetAvalibleProperties(type);
|
||||||
var properties = FilterProperties(propertyInfos);
|
|
||||||
|
|
||||||
var length = reader.ReadStartArray();
|
var length = reader.ReadStartArray();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -441,5 +440,16 @@ namespace mROA.Cbor
|
|||||||
|
|
||||||
return finalProperties;
|
return finalProperties;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<PropertyInfo> GetAvalibleProperties(Type type)
|
||||||
|
{
|
||||||
|
if (_propertiesCache.TryGetValue(type, out var properties))
|
||||||
|
{
|
||||||
|
return properties;
|
||||||
|
}
|
||||||
|
var propertiesList = FilterProperties(type.GetProperties());
|
||||||
|
_propertiesCache[type] = propertiesList;
|
||||||
|
return propertiesList;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -17,7 +17,8 @@
|
|||||||
<RepositoryUrl>https://github.com/YaslePoy/mROA</RepositoryUrl>
|
<RepositoryUrl>https://github.com/YaslePoy/mROA</RepositoryUrl>
|
||||||
<RepositoryType>git</RepositoryType>
|
<RepositoryType>git</RepositoryType>
|
||||||
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
|
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
|
||||||
<Version>2.0.5</Version>
|
<Version>2.0.6</Version>
|
||||||
|
<PackageIcon>mroaLogo.png</PackageIcon>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
@@ -30,6 +31,10 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="$(OutputPath)\$(AssemblyName).dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />
|
<None Include="$(OutputPath)\$(AssemblyName).dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />
|
||||||
|
<None Update="mroaLogo.png">
|
||||||
|
<Pack>True</Pack>
|
||||||
|
<PackagePath></PackagePath>
|
||||||
|
</None>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 6.3 KiB |
@@ -192,13 +192,10 @@ namespace mROA.Implementation
|
|||||||
|
|
||||||
public async Task SingleReceive(CancellationToken token = default)
|
public async Task SingleReceive(CancellationToken token = default)
|
||||||
{
|
{
|
||||||
Console.WriteLine($"Receive start. Time: {profiler.ElapsedMilliseconds}ms");
|
|
||||||
var len = await ReadMessageLength();
|
var len = await ReadMessageLength();
|
||||||
Console.WriteLine($"Received len {len}. Time: {profiler.ElapsedMilliseconds}ms");
|
|
||||||
var localSpan = _buffer[..len];
|
var localSpan = _buffer[..len];
|
||||||
|
|
||||||
await _ioStream.ReadExactlyAsync(localSpan, cancellationToken: token);
|
await _ioStream.ReadExactlyAsync(localSpan, cancellationToken: token);
|
||||||
Console.WriteLine($"Received. Time: {profiler.ElapsedMilliseconds}ms");
|
|
||||||
profiler.Restart();
|
profiler.Restart();
|
||||||
var message = _serializationToolkit.Deserialize<NetworkMessageHeader>(localSpan, _context);
|
var message = _serializationToolkit.Deserialize<NetworkMessageHeader>(localSpan, _context);
|
||||||
MessageReceived(message);
|
MessageReceived(message);
|
||||||
@@ -218,10 +215,8 @@ namespace mROA.Implementation
|
|||||||
var len = _serializationToolkit.Serialize(message, bodySpan.Span, _context);
|
var len = _serializationToolkit.Serialize(message, bodySpan.Span, _context);
|
||||||
var header = BitConverter.GetBytes((ushort)len);
|
var header = BitConverter.GetBytes((ushort)len);
|
||||||
header.CopyTo(_buffer);
|
header.CopyTo(_buffer);
|
||||||
Console.WriteLine($"Send start. Time: {profiler.ElapsedMilliseconds}ms");
|
|
||||||
var sendingSpan = _buffer[..(len + 2)];
|
var sendingSpan = _buffer[..(len + 2)];
|
||||||
await _ioStream.WriteAsync(sendingSpan, token);
|
await _ioStream.WriteAsync(sendingSpan, token);
|
||||||
Console.WriteLine($"Send. Time: {profiler.ElapsedMilliseconds}ms");
|
|
||||||
profiler.Restart();
|
profiler.Restart();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+9
-1
@@ -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.6</Version>
|
<Version>2.0.7</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>
|
||||||
@@ -14,6 +14,7 @@
|
|||||||
<LangVersion>9</LangVersion>
|
<LangVersion>9</LangVersion>
|
||||||
<Configurations>Debug;Release</Configurations>
|
<Configurations>Debug;Release</Configurations>
|
||||||
<Platforms>AnyCPU</Platforms>
|
<Platforms>AnyCPU</Platforms>
|
||||||
|
<PackageIcon>mroaLogo.png</PackageIcon>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
|
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
|
||||||
@@ -29,4 +30,11 @@
|
|||||||
<PackageReference Include="System.Threading.Channels" Version="9.0.5" />
|
<PackageReference Include="System.Threading.Channels" Version="9.0.5" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<None Update="mroaLogo.png">
|
||||||
|
<Pack>True</Pack>
|
||||||
|
<PackagePath></PackagePath>
|
||||||
|
</None>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 6.3 KiB |
Reference in New Issue
Block a user