jackson、fastjson、kryo、protobuf等序列化效率对比【全】
一、综合性能(序列化+反序列化+大小)
综合排名 | 序列化方式 |
1 | kryo-manual |
2 | protostuff-manual |
3 | protostuff |
4 | protobuf/protostuff |
5 | java-manual |
6 | wobly |
7 | fst-flat-pre |
8 | protostuff-runtime |
9 | protobuf/protostuff-runtime |
10 | wobly-compact |
11 | protostuff-graph |
12 | kryo-flat-pre |
13 | protostuff-graph-runtime |
14 | kryo-flat |
15 | fst-flat |
16 | protobuf |
17 | kryo-opt |
18 | json/fastjson/databind |
19 | smile/jackson/manual |
20 | scala/sbinary |
21 | thrift-compact |
22 | json/jackson/manual |
23 | jboss-marshalling-river-ct-manual |
24 | fst |
25 | kryo-serializer |
26 | msgpack-manual |
27 | thrift |
28 | cbor/jackson/manual |
29 | msgpack-databind |
30 | cbor/jackson/databind |
二、序列化效率
序列化效率排名 | 序列化方式 |
1 | protostuff |
2 | protostuff-manual |
3 | protobuf/protostuff |
4 | kryo-manual |
5 | protostuff-runtime |
6 | kryo-flat-pre |
7 | fst-flat-pre |
8 | protobuf/protostuff-runtime |
9 | kryo-flat |
10 | java-manual |
11 | wobly |
12 | protostuff-graph |
13 | msgpack-manual |
14 | protostuff-graph-runtime |
15 | smile/jackson/manual |
16 | wobly-compact |
17 | fst-flat |
18 | kryo-opt |
19 | json/jackson/manual |
20 | json/fastjson/databind |
21 | msgpack-databind |
22 | protobuf |
23 | json/protostuff-manual |
24 | cbor/jackson/databind |
25 | cbor/jackson/manual |
26 | smile/jackson/databind |
27 | fst |
28 | avro-specific |
29 | json/jackson/databind |
30 | scala/sbinary |
三、反序列化效率
反序列化效率排名 | 序列化方式 |
1 | java-manual |
2 | wobly |
3 | kryo-manual |
4 | fst-flat-pre |
5 | protostuff-manual |
6 | wobly-compact |
7 | protobuf/protostuff |
8 | protostuff |
9 | protobuf/protostuff-runtime |
10 | protostuff-runtime |
11 | protostuff-graph |
12 | protobuf |
13 | protostuff-graph-runtime |
14 | thrift-compact |
15 | kryo-flat-pre |
16 | kryo-flat |
17 | fst-flat |
18 | kryo-opt |
19 | scala/sbinary |
20 | json/fastjson/databind |
21 | thrift |
22 | jboss-marshalling-river-ct-manual |
23 | kryo-serializer |
24 | fst |
25 | smile/jackson/manual |
26 | json/jackson/manual |
27 | msgpack-manual |
28 | cbor/jackson/manual |
29 | smile/jackson+afterburner/afterburner |
30 | msgpack-databind |
四、对象大小
对象Size排名 | 序列化方式 |
1 | kryo-opt |
2 | kryo-manual |
3 | kryo-flat-pre |
4 | avro-generic |
5 | avro-specific |
6 | wobly-compact |
7 | msgpack-databind |
8 | msgpack-manual |
9 | protobuf/protostuff |
10 | protobuf |
11 | protostuff-graph |
12 | protostuff-manual |
13 | protostuff |
14 | thrift-compact |
15 | protobuf/protostuff-runtime |
16 | protostuff-graph-runtime |
17 | protostuff-runtime |
18 | fst-flat-pre |
19 | wobly |
20 | java-manual |
21 | scala/sbinary |
22 | kryo-flat |
23 | kryo-serializer |
24 | jboss-marshalling-river-ct-manual |
25 | jboss-marshalling-river-ct |
26 | fst-flat |
27 | fst |
28 | xml/exi-manual |
29 | smile/jackson/databind |
30 | smile/jackson/manual |
五、总结
Kryo——速度快,序列化后体积小;缺点是跨语言支持较复杂
Protostuff——速度快,基于protobuf;缺点是需静态编译
Protostuff-Runtime,无需静态编译,但序列化前需预先传入schema;缺点是不支持无默认构造函数的类,反序列化时需用户自己初始化序列化后的对象,其只负责将该对象进行赋值
Java——使用方便,可序列化所有类;缺点是速度慢,占空间
具体的对比可以参考这个基线图:
Results - JVM Serializer Benchmarks
效率对比直观图:
An Introduction and Comparison of Several Common Java Serialization Frameworks - Alibaba Cloud Community
首选序列化:Kryo、Protostuff