Why java deserialization is fast as kryo?

738 views
Skip to first unread message

Andy Su

unread,
Oct 22, 2014, 10:16:23 PM10/22/14
to java-serializat...@googlegroups.com
In my test java built-in deserialization speed is almost same with kryo. but serialization kryo speed is 10X fast than java builtin

below is my code:
 
public byte[] serial(SomeClass2 data) throws IOException {
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream(5 * 1024 * 1024);
    ObjectOutputStream objectOutputStream = new ObjectOutputStream(outputStream);
    if (shared) {
      objectOutputStream.writeObject(data);
    } else {
      objectOutputStream.writeUnshared(data);
    }
    outputStream.close();
    return outputStream.toByteArray();
  }

  public SomeClass2 deserial(byte[] data) throws IOException, ClassNotFoundException {
    ByteArrayInputStream in = new ByteArrayInputStream(data);
    ObjectInputStream objectInputStream = new ObjectInputStream(in);
    SomeClass2 instance;
    if (shared) {
      instance = (SomeClass2)objectInputStream.readObject();
    } else {
      instance = (SomeClass2)objectInputStream.readUnshared();
    }
    return  instance;
  


and serialiaztion object is 

class SomeClass2 implements Serializable {
   private String tmpBuffer  = Hashing.goodFastHash(1024 * 4).hashInt(512).toString().substring(0, 512);
}


 Does object data matters?

Kannan Goundan

unread,
Oct 22, 2014, 10:59:48 PM10/22/14
to java-serialization-benchmarking
Yes, the structure of the value you're serializing can have a big effect on performance.

--
You received this message because you are subscribed to the Google Groups "java-serialization-benchmarking" group.
To unsubscribe from this group and stop receiving emails from it, send an email to java-serialization-be...@googlegroups.com.
To post to this group, send email to java-serializat...@googlegroups.com.
Visit this group at http://groups.google.com/group/java-serialization-benchmarking.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages