序列化性能和谷歌Android

序列化性能和谷歌Android

本文介绍了序列化性能和谷歌Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在寻找的建议,以加快序列化的性能,特别是在使用了谷歌Android。对于一个项目,我的工作,我想从一个服务器中继几百对象的Andr​​oid应用程序,和我经历的各个阶段得到我所需要的性能。

I'm looking for advice to speed up serialization performance, specifically when using the Google Android. For a project I am working on, I am trying to relay a couple hundred objects from a server to the Android app, and am going through various stages to get the performance I need.

首先,我尝试了可怕的XML解析器,我砍死在一起使用扫描仪专门为这个项目,(对于一个300KB的文件〜5分钟)加载对象时导致令人难以置信的性能下降。然后我离开了,使我的类实现Serializable并写了对象,我不得不一个文件的ArrayList中。读取该文件到物体的机器人,和你在一起,正在采取文件已经下载的心灵〜15-30秒的〜100KB序列化的文件。我仍然觉得这完全不能接受的Andr​​oid应用程序,因为我的应用程序,需要启动应用程序时加载数据。

First I tried a terrible XML parser that I hacked together using Scanner specifically for this project, and that caused unbelievably slow performance when loading the objects (~5 minutes for a 300KB file). I then moved away from that and made my classes implement Serializable and wrote the ArrayList of objects I had to a file. Reading that file into the objects the Android, with the file already downloaded mind you, was taking ~15-30 seconds for the ~100KB serialized file. I still find this completely unacceptable for an Android app, as my app requires loading the data when starting the application.

我也简单说一下外部化,以及它如何可以提高性能阅读,但我不知道至于怎么一实现它与嵌套类。现在,我想存储下面的类的ArrayList,与嵌套类下面。

I have read briefly about Externalizable and how it can increase performance, but I am not sure as to how one implements it with nested classes. Right now, I am trying to store an ArrayList of the following class, with the nested classes below it.

public class MealMenu implements Serializable{
private String commonsName;
private long startMillis, endMillis, modMillis;
private ArrayList<Venue> venues;
private String mealName;
}

和场馆类:

public class Venue implements Serializable{
private String name;
private ArrayList<FoodItem> foodItems;
}

而FoodItem类:

And the FoodItem class:

public class FoodItem implements Serializable{
private String name;
private boolean vegan;
private boolean vegetarian;
}

如果外部化的方式去提高性能,没有任何信息,当您尝试写出来的Java如何调用对象的方法?我不知道如果我需要实现它的父类,也没怎么我会去的每个对象中的序列化嵌套对象。

IF Externalizable is the way to go to increase performance, is there any information as to how java calls the methods in the objects when you try to write it out? I am not sure if I need to implement it in the parent class, nor how I would go about serializing the nested objects within each object.

推荐答案

不要使用序列化不同的体系结构。你有没有办法知道的Dalvik虚拟机将兼容的序列化到你的服务器的Java版本。即使今天的作品,它不可能与两端升级。总是选择一些专门设计不同的体系结构的工作。

Never use Serializable across architectures. You have no way of knowing if the Dalvik VM will have compatible serialization to your server's Java version. Even if it works today, it might not with upgrades on either end. Always choose something that is designed specifically to work across architectures.

选项包括:

  • 在Protocol Buffers的
  • 在阿帕奇节俭(有效载荷包装,不一定是RPC的东西)
  • XML(你忘了提及你用什么解析器 - 如果你使用DOM,SAX尝试)
  • 在JSON(据说杰克逊JSON解析器比内置的Andr​​oid的org.json分析器更快)

此外,数据,应用程序启动时加载300K是prescription麻烦。请考虑利用SQLite的,让你的数据只需要在一个时间位工作。

Also, loading 300K of data on app startup is a prescription for trouble. Please consider leveraging SQLite to allow you to work with just the bits of data you need at a time.

这篇关于序列化性能和谷歌Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 02:45