Skip to content

Commit

Permalink
nino v2.0.2
Browse files Browse the repository at this point in the history
[Optimisation] More efficient code generation for unmanaged types and arrays
  • Loading branch information
JasonXuDeveloper committed Jul 8, 2024
1 parent ab568e0 commit a1ab9fc
Show file tree
Hide file tree
Showing 44 changed files with 748 additions and 3,394 deletions.
2 changes: 1 addition & 1 deletion Docs/Serialization.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public partial struct NotAutoCollectStruct

> 需要Unity2022.3及以上版本
1. 下载[Nino.unitypackage](Nino.unitypackage)
1. 下载[Nino.unitypackage](/Nino.unitypackage)

2. 导入到Unity

Expand Down
526 changes: 40 additions & 486 deletions Performance/Serialization.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,5 @@ Definite useful and high performance serialisation library for C# projects, espe
NuGet里搜```Nino```

```bash
PM> Install-Package Nino -Version 2.0.1
PM> Install-Package Nino -Version 2.0.2
```
65 changes: 65 additions & 0 deletions src/Nino.Benchmark/Data.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
using System;
using System.Collections.Generic;
using System.Linq;
using MemoryPack;
using MessagePack;
using Nino.Core;

namespace Nino.Benchmark;

[NinoType]
[MemoryPackable]
[MessagePackObject]
public partial class SimpleClass
{
[Key(0)]
public int Id;

[Key(1)]
public string Name { get; set; }

Check warning on line 19 in src/Nino.Benchmark/Data.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Name' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 19 in src/Nino.Benchmark/Data.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Name' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
[Key(2)]
public int[] Numbers { get; set; }

Check warning on line 21 in src/Nino.Benchmark/Data.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Numbers' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
[Key(3)]
public List<DateTime> Dates { get; set; }

Check warning on line 23 in src/Nino.Benchmark/Data.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Dates' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

[Key(4)]
public Dictionary<int, string> Map1;

Check warning on line 26 in src/Nino.Benchmark/Data.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable field 'Map1' must contain a non-null value when exiting constructor. Consider declaring the field as nullable.

[Key(5)]
public Dictionary<int, int> Map2 { get; set; }

Check warning on line 29 in src/Nino.Benchmark/Data.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Map2' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

public static SimpleClass Create()
{
Random random = new Random();
return new SimpleClass
{
Id = random.Next(),
Name = "SimpleClass",
Numbers = Enumerable.Range(0, 100).Select(n => random.Next()).ToArray(),
Dates = Enumerable.Range(0, 10).Select(n => DateTime.Now.AddSeconds(random.Next())).ToList(),
Map1 = Enumerable.Range(0, 10).ToDictionary(n => n, n => n.ToString()),
Map2 = Enumerable.Range(0, 10).ToDictionary(n => n, n => n * 2)
};
}
}

[NinoType]
[MemoryPackable]
[MessagePackObject]
public partial struct SimpleStruct
{
[Key(0)]
public int Id;
[Key(1)]
public DateTime CreateTime;

public static SimpleStruct Create()
{
Random random = new Random();
return new SimpleStruct
{
Id = random.Next(),
CreateTime = DateTime.Now.AddSeconds(random.Next())
};
}
}
42 changes: 19 additions & 23 deletions src/Nino.Benchmark/Nino.Benchmark.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,32 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>enable</Nullable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.13.1" />
<PackageReference Include="Ceras" Version="4.1.7" />
<PackageReference Include="FsPickler" Version="5.3.2" />
<PackageReference Include="Hyperion" Version="0.12.2" />
<PackageReference Include="Jil" Version="2.17.0" />
<PackageReference Include="MsgPack.Cli" Version="1.0.1" />
<PackageReference Include="protobuf-net" Version="3.2.26" />
<PackageReference Include="SpanJson" Version="4.0.1" />
<PackageReference Include="System.Text.Json" Version="8.0.0" />
<PackageReference Include="Utf8Json" Version="1.3.7" />
<PackageReference Include="BenchmarkDotNet" Version="0.13.12"/>
<PackageReference Include="Jil" Version="2.17.0"/>
<PackageReference Include="MemoryPack" Version="1.21.1" />
<PackageReference Include="MessagePack" Version="2.4.35" />
<PackageReference Include="MessagePackAnalyzer" Version="2.4.35">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Newtonsoft.Json.Bson" Version="1.0.2" />
<PackageReference Include="MessagePack" Version="2.5.129" />
<PackageReference Include="Microsoft.NETCore.Runtime.CoreCLR" Version="2.0.8" />
</ItemGroup>
<ItemGroup>
<Reference Include="OdinSerializer">
<HintPath>Serialization\OdinSerializer.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Nino.Core\Nino.Core.csproj" />
<PackageReference Include="protobuf-net" Version="3.2.26"/>
<PackageReference Include="Utf8Json" Version="1.3.7" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Nino.Core\Nino.Core.csproj"/>
<ProjectReference Include="..\Nino.Generator\Nino.Generator.csproj"
OutputItemType="Analyzer"
ReferenceOutputAssembly="false"/>
</ItemGroup>
</ItemGroup>

<ItemGroup>
<Using Include="BenchmarkDotNet.Attributes"/>
</ItemGroup>
</Project>
64 changes: 64 additions & 0 deletions src/Nino.Benchmark/PayloadColumn.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using System;
using BenchmarkDotNet.Columns;
using BenchmarkDotNet.Reports;
using BenchmarkDotNet.Running;


namespace Nino.Benchmark;
public class PayloadColumnAttribute : ColumnConfigBaseAttribute
{
public PayloadColumnAttribute()
: base(new PayloadColumn())
{
}
}

public class PayloadColumn : IColumn
{
public string Id => nameof(PayloadColumn);

public string ColumnName => "Payload";

public bool AlwaysShow => true;

public ColumnCategory Category => ColumnCategory.Custom;

public int PriorityInCategory => 0;

public bool IsNumeric => true;

public UnitType UnitType => UnitType.Size;

public string Legend => "Payload size";

public string GetValue(Summary summary, BenchmarkCase benchmarkCase)
{
var methodInfo = benchmarkCase.Descriptor.WorkloadMethod;

if (methodInfo.ReturnType == typeof(byte[]))
{
var instance = Activator.CreateInstance(benchmarkCase.Descriptor.Type);
var result = (byte[])methodInfo.Invoke(instance, null)!;
return new SizeValue(result.LongLength).ToString(null);
}
else
{
return "-";
}
}

public string GetValue(Summary summary, BenchmarkCase benchmarkCase, SummaryStyle style)
{
return GetValue(summary, benchmarkCase);
}

public bool IsAvailable(Summary summary)
{
return true;
}

public bool IsDefault(Summary summary, BenchmarkCase benchmarkCase)
{
return false;
}
}
6 changes: 1 addition & 5 deletions src/Nino.Benchmark/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@ public class Program
{
public static void Main(string[] args)
{
#if !DEBUG
BenchmarkRunner.Run<SerializationBenchmark>();
#else
BenchmarkRunner.Run<SerializationBenchmark>(new BenchmarkDotNet.Configs.DebugInProcessConfig());
#endif
BenchmarkRunner.Run(typeof(Program).Assembly);
}
}
}
163 changes: 0 additions & 163 deletions src/Nino.Benchmark/Serialization/BenchmarkConfig.cs

This file was deleted.

Loading

0 comments on commit a1ab9fc

Please sign in to comment.