Golang Serialization Benchmark 2020 Edition
These benchmark results taken from electhomas’ repo, have a quite interesting result (new serialization formats). Let’s see how much serialization cost, the fastest:
As we can see, Mum, Gencode, Colfer, Bebop, Gotiny, XDR2, MsgPack wins in terms of performace, in cost of serialization size. Let’s check the deserialization performace, the fastest are:
In this part, Bebop, XDR2, Gencode, Colfer, Mum, Gogoprotobuf, Gotiny, FlatBuffers, MsgPack wins this part. So if your bandwidth is unlimited, you can choose these format as your serialization format. You can access the reformatted spreadsheet here. Here’s combined result of serialization and deserialization and addition of serialization size and allocation needed to deserialize.
Here are the links for high performing libraries used:
- Bebop codegen from .bop (need to create schema like protobuf)
- Gencode codegen from .schema (similar to go syntax)
- XDR2 codegen version (other libs are using reflection/automatic), unmaintained
- Mum manual (must create the method to serialize and deserialize yourself), new name is enkodo
- Colfer codegen from .colf (similar to go syntax)
- Gogoprotobuf codegen from .proto
- Gotiny codegen, not recommended for production
- MsgPack codegen version (other libs are using reflection/automatic), from .go source file using go:generate, supported in lots of language
- FlatBuffers codegen, can be used in gRPC
What are the difference between codegen, automatic, manual?
- codegen means there are step to generate golang function by writing a schema definition file then run a program to convert that file to specific programming language implementation, sometimes using other format (so you cannot add custom tag to generated .go file), sometimes using golang struct with tag (like codegen version of msgpack above you need to label each property with , so you can add your own custom tag on the struct property, eg. `json:”bar,omitempty” form:”baz” bson:”blabla”` )
- manual means you must write the serialization and deserialization yourself for each property of the struct (the library only the helper), this allows highly flexible system, so for example you read 1 byte first, then if the value is 1 then you read a string, if 2 you read int32, and so on. This can also be useful to parse network packet if having the same endian.
- automatic means you don’t need to write any schema, it uses reflection so should be slower than codegen version.
Originally published at http://kokizzu.blogspot.com.