I'm reading Java Performance: The Definitive Guide, in the Overriding Default Serialization
section, the author declared that, deserializing the following class
public class Point implements Serializable {
private int x;
private int y;
...
}
is 30% slower than deserializing the following class
public class Point implements Serializable {
private transient int x;
private transient int y;
....
private void writeObject(ObjectOutputStream oos) throws IOException {
oos.defaultWriteObject();
oos.writeInt(x);
oos.writeInt(y);
}
private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException {
ois.defaultReadObject();
x = ois.readInt();
y = ois.readInt();
}
}
Why? I think the time spent deserializing them should be equal because the second class doesn't do anything special.