dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.

Home Page:https://docs.microsoft.com/dotnet/core/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add a good Binary Serializer

VenkateshSrini opened this issue · comments

The BinaryFormatter is now marked as obsolete. Though there are many Serializer like MessagePack and Protobuf. Each have its overhead and limitation when performing serialization. I would suggest the .NET team to look into MessagePack Serialization kind of implementation with support for polymorphic serialization and compression OOB. In case where there is possibility of UnSafe serialization that might happen, they can be shown as compiler warnings which developer can correct.

Though there are many Serializer like MessagePack and Protobuf. Each have its overhead and limitation when performing serialization.

They are just "good" serializers. The limitations are something you must pay for.

support for polymorphic serialization

This is where danger comes.

compression OOB

This is another layer that can be done separately. It will definitely harm performance for real cases. If you data can reach the size to benefit from compression, you should probably use database-like solutions.

The overhead of MessagePack and Protobuf-like serializers are close to minimal for making a "correct" serializer. Dumping memory blocks is fundamentally incorrect for persisted storage.

BinaryFormatter wasn't necessarily a more-performant serializer, and there's nothing inherently more performant about how it worked compared to third-party packages. The fundamental unsafety was unrelated to performance (and entirely due to how it worked generally).

Not everything has to live in CoreLib or extension packages of .NET itself. Binary serialization is a perfect example of specialized solution that is best served by standalone libraries. Besides MessagePack, there are multiple performant binary serde packages for .NET like MemoryPack.