msgpack / msgpack-cli

MessagePack implementation for Common Language Infrastructure / msgpack.org[C#]
http://msgpack.org
Apache License 2.0
834 stars 175 forks source link

Serialization performance is very slow in .NET Core #221

Open neuecc opened 7 years ago

neuecc commented 7 years ago

MsgPack-Cli is extremely slow(slower than JSON.NET!) in .NET Core. I think MsgPack-Cli is using reflection based serializer in .NET Core.

public class MyClass
{
    public int MyProperty { get; set; }
}

class Program
{
    static void Main(string[] args)
    {
        var serializer = MsgPack.Serialization.SerializationContext.Default.GetSerializer<MyClass>();

        // MsgPack.Serialization.ReflectionSerializers.ReflectionObjectMessagePackSerializer`1[[]]
        Console.WriteLine(serializer.GetType().FullName);
    }
}
neuecc commented 7 years ago

Here is csproj, launch VS2017 -> Reference NuGet -> Run.

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp1.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="MsgPack.Cli" Version="0.9.0-beta2" />
  </ItemGroup>

</Project>
Salgat commented 6 years ago

Same here. I was excited to find this project to improve our performance but wow for larger objects it's as bad as 8x slower to serialize versus JSON.NET...

yfakariya commented 6 years ago

How large is it? I want to measure and investigate it.

Salgat commented 6 years ago

The size of the serialized object's file was 220MB versus 300MB serialized as a json file by JSON.NET. The vast majority of the slowdown for MessagePack is serializing (deserializing is fast). The object format (if it matters) was,

class DataSet {
  IDictionary<Guid, Class1> Class1;
  IDictionary<Guid, Class2> Class2;
}

class Class1 {
  string Property1;
  ISet<Guid> Property2;
}

class Class1 {
  string Property1;
  ISet<Guid> Property2;
  Guid Property3; 
}

With 1000 Class1 entries and 1000 Class2 entries, with each entry having 1000 guids in Property2.