Ok I spent alot of time over the weekend working on this. And I'm out
of options.
I profiled it and most of the time is spend on writeObject as
expected. This game has a large object graph with cyclic references
and hence it is taking 52 seconds on the emulator to serialize and
about half to deserialize.
I though I would go through my classes and explicity create a
writeObject() and readObject() functions where I explicility write out
all the fields myself.
private void writeObject(ObjectOutputStream out) throws
IOException {
out.writeObject(board);
out.writeObject(guesser);
out.writeObject(planner);
out.writeInt(possibleMoves.size());
for(int i=0; i<possibleMoves.size(); i++) {
out.writeObject(possibleMoves.elementAt(i));
}
out.writeInt(lastCaptureCounter);
out.writeInt(aiSkillLevel);
}
private void readObject(ObjectInputStream in) throws IOException,
ClassNotFoundException {
board = (StrategoBoard) in.readObject();
guesser = (Guesser) in.readObject();
planner = (Planner) in.readObject();
int length = in.readInt();
possibleMoves = new Vector<Move>(length);
for(int i=0; i<length; i++) {
possibleMoves.add(i, (Move) in.readObject());
}
lastCaptureCounter = in.readInt();
aiSkillLevel = in.readInt();
}
The above is just an example of one of the many classes I have done
this to.
I was hoping this would be quicker. However because I still have to
call writeObject() it seems like I am not saving any time according to
the profiler there isn't any noticeable difference in speed. So I
started looking into other alternatives like xstream but that didnt
work as it couldn't serialize some of my fields in my class but it is
calling writeObject so doubt it will be any faster.
So what are my alternatives to not using Java serialization? I can
probably convert Serializable to Externalizable and then call the
writeExternal and readExternal functions directly myself as they are
public functions. However do you think this will be any faster? Also
if I am doing this, I am not sure how to handle references to objects.
I don't really want to serialize X copies of the same thing, as then
the code will most likely be broken once it is deserialized.
Any suggestions are greatly welcome. I'm out of ideas and quite new to
serialization. I have in my research come across
http://www.eishay.com/2009/03/more-on-benchmarking-java-serialization.html
protobuf seems like it is fast but slow in object creation. Would you
recommended doing it this way? I'm confused. :S
On Jul 30, 11:53 am, rukiman <[email protected]> wrote:
> I must have been very very patient the first time round or lost track
> of time because last night, I got back to the game and timed
> theserializationand it took about a min from hitting the back key to
> displaying the menu! Also this delay didn't exist until my recent
> changes to do with theserialization.
>
> I will profile tonight or tomorrow and report back my findings.
>
> On Jul 29, 6:14 am, Dan Bornstein <[email protected]> wrote:
>
> > On Mon, Jul 27, 2009 at 9:24 PM, Dianne Hackborn <[email protected]>
> > wrote:
> > > On Mon, Jul 27, 2009 at 8:35 PM, rukiman <[email protected]>
> > > wrote:
> > >> Yes I did mean Javaserialization. Any reason why I can't use it
> > >> (apart from it beingslow) ?
>
> > > Um... it being super-crazyslow? :)
>
> > It's also very fragile, in that small innocuous-seeming changes to
> > your code could subtly break yourserialization, and, worse, small
> > innocuous-seeming changes to the platform code could also break it. We
> > on the Android team of course endeavor not to break application code,
> > but we are not perfect by any stretch of the imagination, and
> >serializationis a known tricky area to get right.
>
> > Personally, I might useserializationwhen prototyping a system, but I
> > would be very reluctant to include its use in a finished product.
>
> > All that being said, if you happen to profile yourserialization-using
> > code and find that the slowness is directly due to code in the core
> > library (classes in java.*, javax.*, or org.apache.*), I would
> > appreciate a bug report detailing your observations.
>
> > Cheers,
>
> > -dan
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---