For a long time, Kryo has been the fastest serialization framework in the Java environment and has been widely used.

Zfoo Protocol is a new challenger, so zfoo, Kryo and Protobuf are tested for speed, performance and size.

Serialization: Converting Java objects into binary Byte arrays Deserialization: Converting binary Byte arrays into Java objects In RPC applications, special serialization techniques are required for cross-process remote calls. Objects transmitted over the network need to be serialized and deserialized. There are two main factors affecting serialization and deserialization choices: 1. The size of the stream after serialization, if too large, will affect the performance of network transmission. 2. Performance of serialization and deserialization processesCopy the code
  • This article focuses on performance and serialized size

ⅰ. Performance test

  • The test environment
  • Test code address
Operating system: Win10 CPU: I9900K Memory: 64GCopy the code

ⅱ. Serialization and deserialization sizes

Simple object, zfoo package size 8, Kryo package size 5, Protobuf package size 8 Regular object, Zfoo package size 547, Kryo package size 594, Protobuf package size 984 Complex object, Zfoo package size 2214, Kryo package size 2525, Protobuf Package size 5091Copy the code

ⅲ. Object Definition

  • The simple object
public class SimpleObject implements IPacket {

    public static final transient short PROTOCOL_ID = 1163;

    private int c;
    private boolean g;
}
Copy the code
  • Ordinary objects
public class NormalObject implements IPacket {

    public static final transient short PROTOCOL_ID = 1161;

    private byte a;
    private byte[] aaa;
    private short b;
    private int c;
    private long d;
    private float e;
    private double f;
    private boolean g;
    private String jj;
    private ObjectA kk;

    private List<Integer> l;
    private List<Long> ll;
    private List<ObjectA> lll;
    private List<String> llll;

    private Map<Integer, String> m;
    private Map<Integer, ObjectA> mm;

    private Set<Integer> s;
    private Set<String> ssss;
}
Copy the code
  • Complex object
public class ComplexObject implements IPacket {

    public static final transient short PROTOCOL_ID = 1160;

    private byte a;
    private Byte aa;
    private byte[] aaa;
    private Byte[] aaaa;

    private short b;
    private Short bb;
    private short[] bbb;
    private Short[] bbbb;

    private int c;
    private Integer cc;
    private int[] ccc;
    private Integer[] cccc;

    private long d;
    private Long dd;
    private long[] ddd;
    private Long[] dddd;

    private float e;
    private Float ee;
    private float[] eee;
    private Float[] eeee;

    private double f;
    private Double ff;
    private double[] fff;
    private Double[] ffff;

    private boolean g;
    private Boolean gg;
    private boolean[] ggg;
    private Boolean[] gggg;

    private char h;
    private Character hh;
    private char[] hhh;
    private Character[] hhhh;

    private String jj;
    private String[] jjj;
    private ObjectA kk;
    private ObjectA[] kkk;


    private List<Integer> l;
    private List<List<List<Integer>>> ll;
    private List<List<ObjectA>> lll;
    private List<String> llll;
    private List<Map<Integer, String>> lllll;

    private Map<Integer, String> m;
    private Map<Integer, ObjectA> mm;
    private Map<ObjectA, List<Integer>> mmm;
    private Map<List<List<ObjectA>>, List<List<List<Integer>>>> mmmm;
    private Map<List<Map<Integer, String>>, Set<Map<Integer, String>>> mmmmm;

    private Set<Integer> s;
    private Set<Set<List<Integer>>> ss;
    private Set<Set<ObjectA>> sss;
    private Set<String> ssss;
    private Set<Map<Integer, String>> sssss;
}
Copy the code

Conclusion Ⅳ.

Zfoo has a significant advantage over Kryo and Protobuf in both speed and serialized size, so if you have a very high performance requirement, consider Zfoo. Zfoo will give you a different experience and surprise.

  • Zfoo&java & Netty&RPC & Vuetify High performance Learning Communication Group: 876280300
  • Zfoo open source address github.com/zfoo-projec…

ⅴ. Why not choose XML or Json for comparison

  • The benefits of XML serialization are readability, ease of reading, and debugging. However, after serialization, it is a string, so the size of serialization is relatively large, and the efficiency is not high. Therefore, it is suitable for scenarios with low performance
  • Json is a lightweight data interchange format and very readable. But because it is also a string serialization framework, compared with the binary serialization framework, the efficiency will still be hundreds of times less, the size of serialization is also dozens of times larger