[android-developers] Re: High performance access on static data: What is your approach?
Hi Steve,
of course the parsing of the data with C code would be much faster.
But this only is a workaround and therefore is not acceptable if
compatibility is important. And like with SQLite the Java data
structure has to be copied into another format, which means additional
work if the data structure is modified.
Take, for example, the following data structure:
class A {
int a;
double b;
int[] c;
B[] refs;
}
class B {
double a;
double b;
String s;
int i;
C[] refs;
}
class C {
/* ... */
}
The data structure is really simple, but there are references. If I
know create my own SQLite structure I have to create a table for every
class, update references on my own (because FOREIGN KEY does not work
here), handle special values like null references etc. The procedure
is at least comparable to other formats.
Using serialization, I just store an instance of A to a file and my
complete data structure is saved. It just is much too slow in Dalvik
right now.
Regards
Marc Reichelt || http://www.marcreichelt.de/
On 27 Nov., 12:17, Rockthesmurf <Rockthesm...@hotmail.com> wrote:
> I package up all my files in to a single file - rename it to mp3 and
> put it in res/raw. I then get get file descriptor/offset/size and pass
> it over JNI to C code which I can then access the files data at an
> acceptable speed. My APK is around 10MB.
>
> Steve
>
> On Nov 24, 8:09 am, Marc Reichelt <mcreich...@googlemail.com> wrote:
>
> > Hi!
>
> > I am writing a program where I have to access some static data, and
> > now I am looking for the best method of how to include them into the
> > project.
>
> > This is what I found out by now:
>
> > 1. Reading in the data by parsing an XML is *slow* (even using the SAX
> > parser).
> > 2. Reading the data by parsing a CSV file is faster than loading an
> > XML, but again is too slow.
> > 3. Putting the data into a Java file directly (e.g. by defining an
> > array) fails because Dalvik says it is too large.
> > 4. Reading in the data using serialization is slow. The funny thing
> > here is: It takes a bit longer than loading the XML file.
> > 5. Reading in the data from a SQLite database is the fastest method
> > until now. But a bad workaround is needed: A SQLite DB can not yet be
> > read directly from the resources, but instead has to be copied to the
> > cache or to the SD card - even for read-only access.
>
> > Right now I am using method 5, but I would really like to use a more
> > simplified and faster solution.
>
> > What I found out: Unserialization in Java is *fast* (reading a HashMap
> > with 5000 integers and strings in 79ms on my PC), while the same
> > action on my G1 takes over 13500ms. I know that I can not compare a PC
> > to a mobile device. But still, there seems to be a big difference
> > here. I think that the JRE directly copies the serialized data to RAM,
> > while Dalvik seems to read every object step by step. Is this going to
> > change in the future?
>
> > And, most interestingly: what do you do to access lots of static
> > information?
>
> > Thanks in advance & happy hacking
>
> > Marc Reichelt || http://www.marcreichelt.de/
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home