This project benchmarks the performance of various Java serialization frameworks:
- SimpleBuffer (simple write, read string, varInt)
- Google FlatBuffers
- Google ProtoBuf
- Kryo
- Apache Fory
It measures serialization time, deserialization time, combined serialize+deserialize time, and serialized size.
All benchmarks were performed using the following PlayerModel instance:
PlayerModel baseModel = new PlayerModel(
UUID.randomUUID().toString(),
"Awake",
230,
new ArrayList<>(List.of(1, 2, 3, 4, 5, 7, 8))
); | Framework | Serialize Time (ms) | Deserialize Time (ms) | Serialize + Deserialize Time (ms) | Serialized Size (bytes) | LOC |
|---|---|---|---|---|---|
| SimpleBuffer | 14,517 | 9,372 | 23,304 | 59 | 33 |
| FlatBuffers | 33,141 | 9,870 | 44,269 | 124 | 36 |
| ProtoBuf | 22,725 | 11,349 | 28,995 | 57 | 21 |
| Kryo | 59,885 | 53,198 | 117,350 | 55 | 21 |
| Apache Fory | 7,420 | 10,129 | 18,779 | 63 | 15 |
- Apache Fory has the fastest serialization but slightly slower deserialization.
- SimpleBuffer and ProtoBuf show balanced performance with small serialized sizes.
- Kryo slows down significantly on high iteration counts, likely due to reflection overhead and dynamic class handling.
- FlatBuffers produces larger serialized data but deserializes efficiently.
- Track memory usage with
Runtime.getRuntime(). - Measure throughput (operations/sec) and average latency.
- Perform a JVM warm-up before the main benchmark to allow JIT compilation.
- Test with smaller batches (e.g., 1M iterations) to analyze scalability.
- SimpleBuffer – Lightweight and fast for basic models.
- FlatBuffers – Zero-copy deserialization, slightly larger data.
- ProtoBuf – Well-known, efficient, moderate speed.
- Kryo – Flexible but slower for massive iterations.
- Apache Fory – Code-generated serialization, extremely fast serialization speed.