views:

60

answers:

2

My application requires me to store sets of bits along with some accompanying metadata on the Android platform (read only for now). Now obviously I could just implement the Serializable interface, but I hear it's very slow on Android (I can imagine has to do something with the custom VM and compiler that makes such reflective features inefficient). Should I:

  1. Use Android's Parcel system which seems to be an "assisted" marshalling technique.
  2. Use a custom binary format (maybe BMP style with the header information stripped).
  3. Store into an XML file manually, use XML parser to retrieve data.

Now from what I understand XML serialization or parcelization isn't really backwards compatible on Android? The appeal of XML is of course that these persistent files could be edited in a regular text editor. Which leaves me in a difficult position, since I hate writing code that is redundant.

At this point I am heavily leaning towards the first option (i.e. bitset being parcelized). Any experienced Java/Android programmers care to tell me how well I can expect this to perform? Would I have to expand the bitset into an array of booleans to get acceptable runtime performance? Of course the problem with this is that even a rudimentary benchmark would have to be run on the Dalvik VM since I can't expect Sun's VM on x86 have similar performance to Android on ARM. How does the Android emulator work? Is it a VM on top of the x86 host or does it emulate the ARM instruction set and run the VM targeted at ARM?

I hope this ADD post didn't confuse everyone because it confused me. :D

A: 

I think the 3rd option would be the best since in BitSet even though its less memory consuming in some cases it can simply waste space if you store in binary mode,an example is:


BitSet b=new BitSet();
b.set(100000);

In this case you have only one set bit but it will simply waste space for all the unset bit's when you store in file either as bitmap or in serialized format.Anroid's parcel system I'm not aware about how it works so i can't comment on it.

If you are sure the bits won't be big numbers then go for the the binary mode else go for the XML mode or simply text where you store b.toString() and parse it from file when required.

Emil
+1  A: 

you heard a rumor that serialization is slow, so you're going to use XML? lol.

you need to write yourself some realistic benchmarks, serializing the kinds of bitsets you actually need to deal with (large versus small, dense versus sparse, and so on). i strongly recommend http://code.google.com/p/caliper/ for writing your benchmarks. http://code.google.com/p/vogar/ knows how to run a caliper benchmark on an Android device.

as i say in Designing for Performance, emulator behavior is nothing like device behavior when it comes to performance. you need to test on the lowest-performance device you actually care about.

Elliott Hughes