Alois-xx / SerializerTests

.NET Serializer testing framework
76 stars 22 forks source link

Add MessagePack-Sharp #2

Closed neuecc closed 7 years ago

neuecc commented 7 years ago

Hi, I'm MessagePack-CSharp author. I've read your article and comment. I can't reproduce your comment's exception(Oh...) https://aloiskraus.wordpress.com/2017/04/23/the-definitive-serialization-performance-guide/#comment-86 But I've added my serializer to your benchmark.

Note: MessagePack for C# does not support private field.

Alois-xx commented 7 years ago

Looks good to me. I have merged your changes. In my test I did add a Key attribute only on the public fields of LargeBook but not the private ones. I think that was the main difference between your and my test. That seemed to break something in MessagePack.

neuecc commented 7 years ago

Thanks, and I will investigate contracts that we do not anticipate.

By the way, I forgot to attach the attribute of [MessagePackObject] here. https://github.com/neuecc/SerializerTests/blob/c373120079d92b6a98356556fddf1e542a546b0b/TypesToSerialize/LargeBookShelf.cs#L90 This means that is used string key format(it is slow) If you do measure with LargeObject, I would be happy if you grant it.

Alois-xx commented 7 years ago

How would that affect de/serialization? How big would be the speed gain?

neuecc commented 7 years ago

Just another matter, there is a measured code. https://github.com/neuecc/MessagePack-CSharp/issues/102

Serialize

Method Mean Error StdDev Scaled ScaledSD Gen 0 Allocated
int key 202.5 ns 0.6068 ns 0.5676 ns 1.00 0.00 0.0010 40 B
string key 320.2 ns 0.8527 ns 0.7120 ns 1.58 0.01 0.0015 64 B

Deserialize

Method Mean Error StdDev Scaled ScaledSD Gen 0 Allocated
int key 227.3 ns 1.4442 ns 1.2803 ns 1.00 0.00 0.0042 144 B
string key 439.1 ns 4.2986 ns 4.0209 ns 1.93 0.02 0.0039 144 B

When serializing, int key only write array size header but string key requires each map string key name.

When deserializing, int key can map what type/property to deserialize by switch table but string key requires hashtable lookup.

By the way, if you do a fair serializer speed test, I think that all private fields should be public. The reason for omitting serialization/deserialization of non-targeted fields is that performance differences arise, which is more advantageous.