This document summarizes a presentation on serialization frameworks and their performance. It discusses the purpose of serialization, common data formats like binary, XML, and JSON, and several Java serialization frameworks including Java serialization, Kryo, Protocol Buffers, Jackson, Google GSON, and others. Benchmark results show that Kryo and Protocol Buffers generally have the best performance for serialization and deserialization speed as well as output size. The document provides recommendations on when to use different frameworks based on usage cases and priorities for speed, size, or flexibility.
2. About author
Works in IT since 2000
10 year of Java SE/EE experience
Occupied senior Java developer/Team
Lead positions
Winner of 2013 JBoss Community
Recognition Award.
https://www.jboss.org/jbcra
3. Agenda
• Purpose of serialization
• Frameworks overview
• Performance testing
• Q & A
9. Java serialization
• Serializable interface
• Decreases the flexibility to change a class’s
implementation once it has been released
• Doesn’t allow to exchange data with
C++/Python applications
• Due to default constructors hole for invariant
corruption and illegal access
• No customization
• You should have access to the source code
No customization
You should have access to the source code
10. Java externalization
• Serialization but by implementing
Externalizable interface to persist and
restore the object
• Responsibility of the class to save and
restore the contents of its instances
• Requires modifications in
marshalling/unmarshalling code if the class
contents changed
No customization
You should have access to the source code
16. Simple
• High performance XML serialization and
configuration framework for Java.
• Requires absolutely no configuration
• Can handle cycles in the object graph
20. Json-io
• Doesn’t require custom interfaces/attributes
usage/source code
• Handles cyclic references
• Reader/writer customization
• Does not depend on any native or 3rd party
libraries.
21. Google gson
• Java library to convert JSON to Java objects and
vice-versa
• Doesn’t require source code of serialized objects
• Allow custom representatives
25. BSON for Jackson
• Binary encoded JSON
• Main data exchange format for MongoDB
• Allows writing custom extensions
26. Protocol buffers
• Way of encoding structured data in an efficient
yet extensible format.
• Google uses Protocol Buffers for almost all of
its internal RPC protocols and file formats.
• Supported in Java, C++, Python
27. Protocol buffers
message User {
required string login = 1;
repeated Order orders = 2;
}
message Order {
required int32 id = 1;
optional string date = 2;
}
29. FST
• Java-to-java library
• No support for versioning
• Use case is high performance message oriented
software
• Drop-in replacement
• Custom optimization using annotations, custom
serializers
31. GridGain
• Part of distributed computing system
• Don’t require any custom interfaces or API
• Direct memory copying by invoking native
"unsafe" operations
• Predefined fields introspection
33. Kryo
• Fast and efficient object graph serialization
framework for Java
• Open source project on Google code
• Automatic deep and shallow copying/cloning
• Doesn’t put requirements on the source classes
(in most cases)
51. Advices
Library Usage
Kryo Fast and compact serializer for complex
objects over network
Protocol buffers Fast serializer for simple objects
Jackson(smile) Jackson-based serializer for Web usage
Google JSON Dirty solution to quickly serialize/deserialize
objects
Apache Avro Serialize objects into files with possible
schema changes
Java Out-of-the-box trusted solution without
additional libraries