Skip to content

Commit

Permalink
Merge develop into master
Browse files Browse the repository at this point in the history
  • Loading branch information
AArnott committed Jul 29, 2021
2 parents 1551f93 + 4d61d5d commit 847c581
Show file tree
Hide file tree
Showing 109 changed files with 8,106 additions and 2,893 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Expand Up @@ -32,7 +32,7 @@
<PackageReference Include="Nerdbank.GitVersioning" Version="3.2.7-beta" PrivateAssets="all" />
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="16.5.124-alpha" PrivateAssets="All" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.164" PrivateAssets="all" />
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.261" PrivateAssets="all" />
</ItemGroup>

<Target Name="PrepareReleaseNotes" BeforeTargets="GenerateNuspec" DependsOnTargets="GetBuildVersion">
Expand Down
122 changes: 7 additions & 115 deletions MessagePack.sln

Large diffs are not rendered by default.

22 changes: 21 additions & 1 deletion README.md
Expand Up @@ -184,7 +184,7 @@ These types can serialize by default:
* Primitives (`int`, `string`, etc...), `Enum`s, `Nullable<>`, `Lazy<>`
* `TimeSpan`, `DateTime`, `DateTimeOffset`
* `Guid`, `Uri`, `Version`, `StringBuilder`
* `BigInteger`, `Complex`
* `BigInteger`, `Complex`, `Half`
* `Array[]`, `Array[,]`, `Array[,,]`, `Array[,,,]`, `ArraySegment<>`, `BitArray`
* `KeyValuePair<,>`, `Tuple<,...>`, `ValueTuple<,...>`
* `ArrayList`, `Hashtable`
Expand Down Expand Up @@ -404,6 +404,8 @@ public struct Point
}
```

### C# 9 `record` types

C# 9.0 record with primary constructor is similar immutable object, also supports serialize/deserialize.

```csharp
Expand All @@ -412,8 +414,26 @@ C# 9.0 record with primary constructor is similar immutable object, also support

// use property: to set KeyAttribute
[MessagePackObject] public record Point([property:Key(0)] int X, [property: Key(1)] int Y);

// Or use explicit properties
[MessagePackObject]
public record Person
{
[Key(0)]
public string FirstName { get; init; }

[Key(1)]
public string LastName { get; init; }
}
```

### C# 9 `init` property setter limitations

When using `init` property setters in _generic_ classes, [a CLR bug](https://github.com/neuecc/MessagePack-CSharp/issues/1134) prevents our most efficient code generation from invoking the property setter.
As a result, you should avoid using `init` on property setters in generic classes when using the public-only `DynamicObjectResolver`/`StandardResolver`.

When using the `DynamicObjectResolverAllowPrivate`/`StandardResolverAllowPrivate` resolver the bug does not apply and you may use `init` without restriction.

## Serialization Callback

Objects implementing the `IMessagePackSerializationCallbackReceiver` interface will received `OnBeforeSerialize` and `OnAfterDeserialize` calls during serialization/deserialization.
Expand Down
10 changes: 3 additions & 7 deletions azure-pipelines/build.yml
@@ -1,12 +1,8 @@
steps:
# Use VSBuild to pack because `dotnet pack` can't build VSIX projects.
- task: VSBuild@1
- task: DotNetCoreCLI@2
inputs:
vsVersion: 16.0
solution: MessagePack.sln
msbuildArgs: /t:build,pack /m /v:m /bl:"$(Build.ArtifactStagingDirectory)/build_logs/msbuild.binlog"
platform: $(BuildPlatform)
configuration: $(BuildConfiguration)
command: build
arguments: --configuration $(BuildConfiguration) /t:build,pack /m /v:m /bl:"$(Build.ArtifactStagingDirectory)/build_logs/msbuild.binlog"
displayName: Build MessagePack.sln

- task: DotNetCoreCLI@2
Expand Down
2 changes: 1 addition & 1 deletion azure-pipelines/build_nonWindows.yml
Expand Up @@ -3,7 +3,7 @@ steps:
displayName: Build MessagePack.sln
inputs:
command: build
arguments: --no-restore /p:platform=NoVSIX -c $(BuildConfiguration)
arguments: --no-restore -c $(BuildConfiguration)

- task: DotNetCoreCLI@2
displayName: Run MessagePack.Tests (netcoreapp2.1)
Expand Down
4 changes: 0 additions & 4 deletions azure-pipelines/release.yml
Expand Up @@ -28,9 +28,6 @@ stages:
- download: CI
artifact: unity
displayName: 'Downloading artifact: unity'
- download: CI
artifact: vsix
displayName: 'Downloading artifact: vsix'
- task: GitHubRelease@1
displayName: GitHub release (create)
inputs:
Expand All @@ -42,7 +39,6 @@ stages:
title: v$(resources.pipeline.CI.runName)
assets: |
$(Pipeline.Workspace)/CI/unity/*.unitypackage
$(Pipeline.Workspace)/CI/vsix/*
isDraft: true # After running this step, visit the new draft release, edit, and publish.
changeLogCompareToRelease: lastNonDraftRelease
changeLogType: issueBased
Expand Down
92 changes: 19 additions & 73 deletions benchmark/SerializerBenchmark/BenchmarkConfig.cs
Expand Up @@ -27,13 +27,13 @@ public BenchmarkConfig()
Job baseConfig = Job.ShortRun.WithIterationCount(1).WithWarmupCount(1);

// Add(baseConfig.With(Runtime.Clr).With(Jit.RyuJit).With(Platform.X64));
this.Add(baseConfig.With(CoreRuntime.Core31).With(Jit.RyuJit).With(Platform.X64));
this.AddJob(baseConfig.WithRuntime(CoreRuntime.Core31).WithJit(Jit.RyuJit).WithPlatform(Platform.X64));

this.Add(MarkdownExporter.GitHub);
this.Add(CsvExporter.Default);
this.Add(MemoryDiagnoser.Default);
this.AddExporter(MarkdownExporter.GitHub);
this.AddExporter(CsvExporter.Default);
this.AddDiagnoser(MemoryDiagnoser.Default);

this.Add(new DataSizeColumn());
this.AddColumn(new DataSizeColumn());

this.Orderer = new CustomOrderer();
}
Expand Down Expand Up @@ -96,19 +96,24 @@ public string GetValue(Summary summary, BenchmarkCase benchmarkCase)
public string GetValue(Summary summary, BenchmarkCase benchmarkCase, SummaryStyle style)
{
System.Reflection.MethodInfo mi = benchmarkCase.Descriptor.WorkloadMethod;
if (mi.Name.Contains("Serialize"))
if (!mi.Name.Contains("Serialize"))
{
var instance = Activator.CreateInstance(mi.DeclaringType);
mi.DeclaringType.GetField("Serializer").SetValue(instance, benchmarkCase.Parameters[0].Value);
mi.DeclaringType.GetMethod("Setup").Invoke(instance, null);

var bytes = (byte[])mi.Invoke(instance, null);
return ToHumanReadableSize(bytes.Length);
return "-";
}
else

var instance = Activator.CreateInstance(mi.DeclaringType);
mi.DeclaringType.GetField("Serializer").SetValue(instance, benchmarkCase.Parameters[0].Value);
mi.DeclaringType.GetMethod("Setup").Invoke(instance, null);

var bytes = (byte[])mi.Invoke(instance, null);
var byteSize = bytes.Length;
var cultureInfo = summary.GetCultureInfo();
if (style.PrintUnitsInContent)
{
return "-";
return SizeValue.FromBytes(byteSize).ToString(style.SizeUnit, cultureInfo);
}

return byteSize.ToString("0.##", cultureInfo);
}

public bool IsAvailable(Summary summary)
Expand All @@ -120,65 +125,6 @@ public bool IsDefault(Summary summary, BenchmarkCase benchmarkCase)
{
return false;
}

private static string ToHumanReadableSize(long size)
{
return ToHumanReadableSize(new long?(size));
}

private static string ToHumanReadableSize(long? size)
{
if (size == null)
{
return "NULL";
}

double bytes = size.Value;

if (bytes <= 1024)
{
return bytes.ToString("f2") + " B";
}

bytes = bytes / 1024;
if (bytes <= 1024)
{
return bytes.ToString("f2") + " KB";
}

bytes = bytes / 1024;
if (bytes <= 1024)
{
return bytes.ToString("f2") + " MB";
}

bytes = bytes / 1024;
if (bytes <= 1024)
{
return bytes.ToString("f2") + " GB";
}

bytes = bytes / 1024;
if (bytes <= 1024)
{
return bytes.ToString("f2") + " TB";
}

bytes = bytes / 1024;
if (bytes <= 1024)
{
return bytes.ToString("f2") + " PB";
}

bytes = bytes / 1024;
if (bytes <= 1024)
{
return bytes.ToString("f2") + " EB";
}

bytes = bytes / 1024;
return bytes + " ZB";
}
}
}
}
6 changes: 2 additions & 4 deletions benchmark/SerializerBenchmark/Program.cs
@@ -1,13 +1,11 @@
// Copyright (c) All contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Benchmark;
using Benchmark.Models;
using BenchmarkDotNet.Running;

namespace ConsoleApp1
namespace Benchmark
{
internal class Program
internal static class Program
{
private static void Main(string[] args)
{
Expand Down
64 changes: 32 additions & 32 deletions benchmark/SerializerBenchmark/SerializerBenchmark.cs
Expand Up @@ -21,7 +21,7 @@ public class AllSerializerBenchmark_BytesInOut
[ParamsSource(nameof(Serializers))]
public SerializerBase Serializer;

// Currently BenchmarkdDotNet does not detect inherited ParamsSource so use copy and paste:)
// Currently BenchmarkDotNet does not detect inherited ParamsSource so use copy and paste:)
public IEnumerable<SerializerBase> Serializers => new SerializerBase[]
{
new MessagePack_v1(),
Expand All @@ -31,20 +31,20 @@ public class AllSerializerBenchmark_BytesInOut
new MsgPack_v2_opt(),
//new MsgPack_v2_string(),
//new MsgPack_v2_str_lz4(),
new ProtobufNet(),
new JsonNet(),
new BsonNet(),
new BinaryFormatter_(),
new DataContract_(),
new Hyperion_(),
new Jil_(),
new SpanJson_(),
new Utf8Json_(),
new SystemTextJson(),
new MsgPackCli(),
new FsPickler_(),
new Ceras_(),
new Odin_(),
new ProtobufNetSerializer(),
new JsonNetSerializer(),
new BsonNetSerializer(),
new BinaryFormatterSerializer(),
new DataContractSerializer(),
new HyperionSerializer(),
new JilSerializer(),
new SpanJsonSerializer(),
new Utf8JsonSerializer(),
new SystemTextJsonSerializer(),
new MsgPackCliSerializer(),
new FsPicklerSerializer(),
new CerasSerializer(),
new OdinSerializer_(),
};

protected static readonly ExpressionTreeFixture ExpressionTreeFixture = new ExpressionTreeFixture();
Expand Down Expand Up @@ -569,7 +569,7 @@ public class MsgPackV1_Vs_MsgPackV2_BytesInOut // : AllSerializerBenchmark
[ParamsSource(nameof(Serializers))]
public SerializerBase Serializer;

// Currently BenchmarkdDotNet does not detect inherited ParamsSource so use copy and paste:)
// Currently BenchmarkDotNet does not detect inherited ParamsSource so use copy and paste:)
public IEnumerable<SerializerBase> Serializers => new SerializerBase[]
{
new MessagePack_v1(),
Expand Down Expand Up @@ -1100,7 +1100,7 @@ public class ShortRun_AllSerializerBenchmark_BytesInOut

private bool isContractless;

// Currently BenchmarkdDotNet does not detect inherited ParamsSource so use copy and paste:)
// Currently BenchmarkDotNet does not detect inherited ParamsSource so use copy and paste:)
public IEnumerable<SerializerBase> Serializers => new SerializerBase[]
{
new MessagePack_v1(),
Expand All @@ -1112,20 +1112,20 @@ public class ShortRun_AllSerializerBenchmark_BytesInOut
new MsgPack_v2_string(),
new MsgPack_v1_str_lz4(),
new MsgPack_v2_str_lz4(),
new ProtobufNet(),
new JsonNet(),
new BsonNet(),
new BinaryFormatter_(),
new DataContract_(),
new Hyperion_(),
new Jil_(),
new SpanJson_(),
new Utf8Json_(),
new SystemTextJson(),
new MsgPackCli(),
new FsPickler_(),
new Ceras_(),
new Odin_(),
new ProtobufNetSerializer(),
new JsonNetSerializer(),
new BsonNetSerializer(),
new BinaryFormatterSerializer(),
new DataContractSerializer(),
new HyperionSerializer(),
new JilSerializer(),
new SpanJsonSerializer(),
new Utf8JsonSerializer(),
new SystemTextJsonSerializer(),
new MsgPackCliSerializer(),
new FsPicklerSerializer(),
new CerasSerializer(),
new OdinSerializer_(),
};

protected static readonly ExpressionTreeFixture ExpressionTreeFixture = new ExpressionTreeFixture();
Expand Down Expand Up @@ -1199,7 +1199,7 @@ public class ShortRun_MsgPackV1_Vs_MsgPackV2_BytesInOut
[ParamsSource(nameof(Serializers))]
public SerializerBase Serializer;

// Currently BenchmarkdDotNet does not detect inherited ParamsSource so use copy and paste:)
// Currently BenchmarkDotNet does not detect inherited ParamsSource so use copy and paste:)
public IEnumerable<SerializerBase> Serializers => new SerializerBase[]
{
new MessagePack_v1(),
Expand Down
2 changes: 1 addition & 1 deletion benchmark/SerializerBenchmark/SerializerBenchmark.csproj
Expand Up @@ -10,7 +10,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.12.0" />
<PackageReference Include="BenchmarkDotNet" Version="0.12.1" />
<PackageReference Include="Ceras" Version="4.1.7" />
<PackageReference Include="FsPickler" Version="5.2.2" />
<PackageReference Include="Hyperion" Version="0.9.11" />
Expand Down
29 changes: 0 additions & 29 deletions benchmark/SerializerBenchmark/Serializers/BinaryFormatter.cs

This file was deleted.

0 comments on commit 847c581

Please sign in to comment.