Fast deserialization/reserialization is critical for databases. The key is to deserialize only what you need and to keep the serialized data for items that have not been changed for reserialization after an update.
2. The Problem
● Data is stored on disk as byte arrays, which
may be quite large.
● These arrays must be deserialized before the
data can be updated and then reserialized.
● There are various techniques for deserialization
and reserialization but they are all quite slow as
all the data is deserialized and then
reserialized.
3. Incremental Deserialization and
Reserialization
JID Benchmark results for deserializing, updating and then
reserializing large collections.
Entries List Insertion Map Update
1,000 .014 ms .027 ms
10.000 .035 ms .056 ms
100,000 .24 ms .48 ms
1,000,000 2.9 ms 6.9 ms
High performance is achieved by deserializing only
the data that is needed and reserializing only the
data that has been updated.
4. Types of Serialization
● Many applications use ● Hard-coded serialization
reflection-based directly converst data
serialization. from/to arrays of bytes.
● Reflection-based ● This is harder to
serialization is the implement, but runs
easiest to use, but also faster.
the slowest. ● But mixing applicaiton
● There are three main logic with serialization
types: native logic detracts from the
serialization, XML-based clarity of the code.
and Jason.
5. JID is Complex
● Every JID object must track the serialized data
that has not been outdated and any data that
has been deserialized, along with notifying its
container when there is a change.
● Serializable data structures are trees of JID
objects that are mostly instances of pre-defined
classes.
● Application classes contain no serialization
logic, but subclass a JID vector of homogenious
JID types.
6. Factories
● Registered factory objects are needed to instantiate
and initialize JID objects.
● Each registered facory object represents a different
JID type and has a unique name.
● All factory objects are instances of subclasses of the
JidFactory class.
● Factory objects used to instantiate application JID
objects are instances of subclasses of AppJidFactory.
● These factory objects provide the type names of the
registered factory objects needed to create the tuple
elements of the application objects.
7. User Class
public class User extends AppJid {
private StringJid getNameJid() throws Exception {
return (StringJid) _iGet(0);}
private IntegerJid getAgeJid() throws Exception {
return (IntegerJid) _iGet(1);}
public String getName() throws Exception {
return getNameJid().getValue();}
public void setName(String name) throws Exception {
getNameJid().setValue(name);}
public int getAge() throws Exception {
return getAgeJid().getValue();}
public void setAge(int age) throws Exception {
getAgeJid().setValue(age);}
}
8. UserFactoryClass
public class UserFactory extends AppJidFactory {
final public static UserFactory fac = new UserFactory();
public UserFactory() {
super("User",
JidFactories.STRING_JID_TYPE,
JidFactories.INTEGER_JID_TYPE);
}
protected User instantiateActor()
throws Exception {
return new User();
}
}
9. User Test Environment
public class Apps {
public static void main(String[] args) throws Exception {
JAFactory factory = new JAFactory();
(new JidFactories()).initialize(factory);
factory.registerActorFactory(UserFactory.fac);
.
.
.
}
}
10. Serializing
RootJid rootJid0 = (RootJid)
factory.newActor(JidFactories.ROOT_JID_TYPE);
rootJid0.setValue("User");
User user0 = (User) rootJid0.getValue();
user0.setName("Fred");
user0.setAge(38);
int serializedLength0 = rootJid0.getSerializedLength();
byte[] serializedData0 = new byte[serializedLength0];
rootJid0.save(serializedData0, 0);
11. Deserialization
RootJid rootJid1 = (RootJid)
factory.newActor(JidFactories.ROOT_JID_TYPE);
rootJid1.load(serializedData0, 0, serializedLength0);
User user1 = (User) rootJid1.getValue();
if (!"Fred".equals(user1.getName()))
throw new Exception("unexpected result");
if (38 != user1.getAge())
throw new Exception("unexpected result");