Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hazelcast Serialization nested objects

Hello I am having one question in regards of the latest Hazecast versions and serialization. Lets have the following class:

class Customer implements DataSerializeable {
    List<Address> adresses;
    CustomerDetails details;
}

Both classes Address and CustomerDetails implement DataSerializeable. The way we are serializing them at the moment is:

public void writeData(ObjectDataOutput out) throws IOException {
   out.writeObject(address);
   out.writeObject(details);
}

In some examples online I saw that the way they are serializing the same class is:

public void writeData(ObjectDataOutput out) throws IOException {
   address.writeData(out);
   short size = details.size();
   out.writeShort(size);
   for (CustomerDetail detail: details) {
      detail.writeData(out);
   }

}

I ran some performance test over couple of milion records I was not able to observe significant difference in performance.

What is the recommended way to do serialization of the Nested Objects. Can someone comment on that with regards of the latest Hazelcast version 3.6.

Thank you

like image 690
Alexander Petrov Avatar asked Mar 07 '26 15:03

Alexander Petrov


1 Answers

These days there is no noticeable difference since we have optimized serializers for ArrayList, LinkedList, HashMap. That way you get the almost same benefit as handwriting it.

The ArrayList serializer classes can be found here: https://github.com/hazelcast/hazelcast/blob/master/hazelcast/src/main/java/com/hazelcast/internal/serialization/impl/ArrayListStreamSerializer.java

Looking at the code you'll see, that it'll give you almost the same benefit.

like image 80
noctarius Avatar answered Mar 09 '26 05:03

noctarius