FasterXML / jackson-dataformats-binary

Uber-project for standard Jackson binary format backends: avro, cbor, ion, protobuf, smile
Apache License 2.0
314 stars 136 forks source link

Improve Union type serialization performance #173

Closed marcospassos closed 5 years ago

marcospassos commented 5 years ago

The serialization mechanism currently calls the ReflectData.get().resolveUnion() Method for resolving union schemas. This call represents a huge penalty as it generates the entire schema for the object behind the scenes to get the schema name and find the corresponding index. It's even worse because sometimes it not even possible to generate the schema for the actual value, causing the serialization to fail:

class Foo {
     // The schema for this object cannot be generated, as the type of tricks can be anything.
     // However, for the sake of the serialization, it doesn't matter, as the type has been specified  in the schema
     public Set<?> tricks = new HashSet<>();
}

This issue can be resolved by checking the set of union schema using the class name instead of using ReflectData.get().resolveUnion(). There is already a snippet in the code that does exactly this, but is currently disabled.

marcospassos commented 5 years ago

Fixed