Skip to content
Tech News
← Back to articles

MemoryPack: Zero encoding extreme performance binary serializer for C#

read original more articles
Why This Matters

MemoryPack introduces a highly optimized binary serializer for C# and Unity, achieving up to 200x faster speeds than existing serializers by utilizing zero-encoding and C#-specific formats. Its performance improvements and modern API support make it a significant advancement for developers seeking efficient data serialization in high-performance applications.

Key Takeaways

MemoryPack

Zero encoding extreme performance binary serializer for C# and Unity.

Compared with System.Text.Json, protobuf-net, MessagePack for C#, Orleans.Serialization. Measured by .NET 7 / Ryzen 9 5950X machine. These serializers have IBufferWriter<byte> method, serialized using ArrayBufferWriter<byte> and reused to avoid measure buffer copy.

For standard objects, MemoryPack is x10 faster and x2 ~ x5 faster than other binary serializers. For struct array, MemoryPack is even more powerful, with speeds up to x50 ~ x200 greater than other serializers.

MemoryPack is my 4th serializer, previously I've created well known serializers, ZeroFormatter , Utf8Json , MessagePack for C#. The reason for MemoryPack's speed is due to its C#-specific, C#-optimized binary format and a well tuned implementation based on my past experience. It is also a completely new design utilizing .NET 7 and C# 11 and the Incremental Source Generator (.NET Standard 2.1 (.NET 5, 6) and there is also Unity support).

Other serializers perform many encoding operations such as VarInt encoding, tag, string, etc. MemoryPack format uses a zero-encoding design that copies as much C# memory as possible. Zero-encoding is similar to FlatBuffers, but it doesn't need a special type, MemoryPack's serialization target is POCO.

Other than performance, MemoryPack has these features.

Support modern I/O APIs ( IBufferWriter<byte> , ReadOnlySpan<byte> , ReadOnlySequence<byte> )

, , ) Native AOT friendly Source Generator based code generation, no Dynamic CodeGen (IL.Emit)

Reflectionless non-generics APIs

... continue reading