Android persisting data - Serialization vs Jackson+JSON
My Android app stores data using ObjectOutputStream in files. We made a
conscious decision to not use a DB. I've read up recently that
Serialization on Android is considered very slow. Also, that using Jackson
+ JSON is considered fast. However after incorporating Jackson/JSON it
seems that storing POJOs in files with Jackson/JSON is not at all faster
and sometimes even slower that Serialization. I'm using the core library
for Jackson v2.2
I've also tried using ObjectWriters and ObjectReaders, but that doesn't
provide any significant speed benefit. I'm using the following settings
for ObjectMapper (I create one globally):
mapper.setVisibility(JsonMethod.FIELD, Visibility.ANY);
mapper.setVisibility(JsonMethod.GETTER, Visibility.NONE);
mapper.setVisibility(JsonMethod.SETTER, Visibility.NONE);
mapper.setVisibility(JsonMethod.IS_GETTER, Visibility.NONE);
mapper.configure(SerializationConfig.Feature.USE_ANNOTATIONS, false);
mapper.configure(DeserializationConfig.Feature.USE_ANNOTATIONS, false);
When I say that there is no speed benefits what I'm timing is taking about
~400 POJOs and storing them in separate files. I'm currently timing
Serializtion and writing to files as opposed to the opposite. Half of
these POJOs are rather complex (with references to lists of other POJOs).
I'm testing on a device (Galaxy Tab 10-1 running Android 4.1). With both
Serialization and Jackson/JSON the process takes about 6 seconds with
difference between the two approaches following within margin of error
(variation on repeated test runs).
Any advice on how it's possible that "very slow Serialization" on Android
could be roughly the same as "very fast" Jackson/JSON? Is there some
approach that could significantly speed up Jackson?
No comments:
Post a Comment