This article is a mirror article of machine translation, please click here to jump to the original article.

View: 14559|Reply: 0

[Source] Java kryo/protobuf/protostuff serialization or JSON performance comparison

[Copy link]
Posted on 7/15/2019 9:16:23 PM | | |
For the serialization of a Java object, I would like to test the difference between using JSON and using general serialization tools in terms of temporal and spatial performance.

json chooses to use fastjson.

The serialization tool uses Protostuff and Kyro. Why not use protobuf? Because I feel that for a java class with hundreds of existing properties, creating a new matching proto file is a bit anti-human. Protostuff is an improved version of Protobuf, which allows you to serialize a Java Object directly, using it in a bit like Kyro, without as many intermediate processes as Protobuf. Others, such as Hession, Java with serialization, etc., are said to have much worse performance than Kryo and Protobuf, so I don't know what to expect.

After a simple test, I found that the gap was quite obvious, so I felt that there was no need to do a specific evaluation. Cut a paragraph of the log and send it out, everyone feel it.

cost time is System.nanoTime(); All three are the default configurations without any configuration.
The space footprint after serialization is slightly lower than that of protostuff, and both are much higher than JSON. This is easy to understand, after all, json strings are readable, don't force too much.
The time required for serialization and deserialization is better than Kyro over FastJSON, and the difference is quite obvious.

So in conclusion, if there are no extremely demanding requirements for space, Protostuff may be the best choice. Protostuff has an additional advantage over Kyro, that is, if the java class adds fields after serialization and before deserialization (which is unavoidable in real business), Kyro will be useless. However, protostuff can be used as long as it is added at the end of the class and uses the sun series JDK. Therefore, if serialization is used in scenarios such as cache, and the serialized object needs to be stored for a long time, you can only choose protostuff.

Of course, if there is a need for readability or something, you can only use json.




Previous:asp.net Customize the session id name
Next:Comparison of Protobuf and JSON performance under .NET platform
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com