RuedigerMoeller / fast-serialization

FST: fast java serialization drop in-replacement
Apache License 2.0
1.59k stars 247 forks source link

Serializing doubles memory usage on Android #243

Open xbit opened 6 years ago

xbit commented 6 years ago

When trying to serialize a complicated Object that has a huge HashMap the memory usage is doubled. The memory goes from 200MB to about 405MB. I'm serializing it this way:

FileOutputStream fileOut = ....
FSTObjectOutput  objectOut = new FSTObjectOutput(fileOut);
objectOut.writeObject(object, SerializableObject.class);
....
objectOut.close();

Is there a way to lower memory usage when serializing? Or am I doing something wrong?

RuedigerMoeller commented 6 years ago

fst allocates a byte array buffering at least the complete output of a stream for performance reasons. As its a single object, it has practically no drawback on GC duration, however there still is a peak in mem consumption.

In order split this. one could write key, values of a hashmap using FSTConfiguration.asByteArray(..) and write those to an ordinary ouput stream, however object link restoration (links to same objects) won't work this way.