iPhone网络性能 [英] iPhone network performance

查看:30
本文介绍了iPhone网络性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,我很愿意接受建议(甚至很奇怪!)

I have a question and I am very open to suggestions (even very odd ones!)

我正在编写一个iPhone应用程序,该应用程序向服务器发出请求(带有参数的URL).作为响应,iPhone接收XML.一切都很好.

I am writing an iPhone app, which does a request (URL with parameters) to a server. As a response, the iPhone receives XML. All is well.

现在,我希望通过测量执行某些任务所需的时间来提高应用程序的速度.我发现,在执行的所有任务(下载,XML解析,发送请求,处理请求,从XML解析对象)中,下载实际的XML花费的时间最长.

Right now, I am looking to improve my application's speed by measuring the time it takes to perform certain tasks. I've found that, of all the tasks performed (downloading, XML Parsing, sending the request, handeling the request, parsing objects from XML), downloading the actual XML takes the longest.

现在,我的XML文件非常非常非常容易,非常非常非常小.我主要使用它们来读取类似RSS的数据并将其显示在UITableView中.

Now, my XML files are very, very, very easy and very, very, very small. I use them primarily to read RSS-like data and show them in a UITableView.

我的应用程序运行良好,没有什么感觉真的很慢,但是现在App Store中有一个应用程序与我的应用程序功能非常相似,但是速度更快并且感觉更贪婪"(如果有)你知道我的意思.它还具有很棒的功能,可以从RSS提要中逐个加载标题.

My app works very well, and there is nothing that feels really slow, but there is one application in the App Store right now which does something very similar to my application, but is way faster and feels more 'snappy', if you know what I mean. It also has the great feature to load the headlines one by one from the RSS-feed.

当前,我正在尝试对数据进行gzip压缩,但是压缩仅使我的数据大小减小一半,而且似乎对性能没有任何真正的好处.最主要的是,在解析数据之前,必须先下载数据.拥有一个数据流",并对其进行解析将非常酷.这样,我几乎可以同时完成两项工作,并一一载入标题(使用户交互更具吸引力).

Currently I'm experimenting with gzip compression of my data, but the compression only makes my data half the size and it doesn't seem to do any real good for performance. The main thing is, that the data has to be downloaded, before it gets parsed. It would be very cool to have a 'stream' of data, which is parsed as it comes in. That way, I can do two jobs almost simultaneous and load headlines one by one (making user interactivity more attractive).

任何人都有一个如何提高我的表现的想法?要么通过强大的压缩技巧,要么以完全不同的方式与服务器进行通信.欢迎所有!

Anyone has an idea of how to improve my performance? Either by great compression tips or entirely different ways to communicate with the server.. All is welcome!

更新:将服务器的延迟和响应能力放在一边;如何获取XML源以流式传输"到iPhone(逐字节下载)并同时进行解析?目前,它是下载->解析->显示的线性过程,但通过下载&同时解析(并在下载完成后显示每个项目,而不是同时在UITableView中加载所有项目)

UPDATE: putting the latency and responsiveness of the server aside; how could I get a source of XML to be 'streamed' to my iPhone (downloaded byte for byte) and at the same time get parsed? Right now it is a linear process of downloading -> parsing -> showing, but it could become semi-parallel by downloading & parsing at the same time (and show each item when it is done downloading, instead of loading it all at the same time in a UITableView)

推荐答案

假设您使用的是NSXMLParser的initWithContentsOfURL :,则可能是问题的一部分.似乎是下载了URL的全部内容,然后将其交给解析器以一次解析所有内容.

Assuming you're using NSXMLParser's initWithContentsOfURL:, that's probably part of the problem. It seems like that downloads the entire contents of the URL, then hands it off to the parser to parse all at once.

尽管NSXMLParser是事件驱动的解析器,但它似乎并不支持以增量方式将数据流传输到解析器.当然,您可以将NSXMLParser替换为其他解析库,以更明智的方式处理增量数据.

Despite the fact that the NSXMLParser is an event-driven parser, it doesn't seem to support streaming data to the parser in an incremental manner. You could, of course, replace NSXMLParser with some other parsing library that handles incremental data in a more sensible way.

一种替代方法是使用NSURLConnection,并在NSURLConnection委托的connection:didReceiveData:方法中,每次输入一些数据时创建一个新的NSXMLParser并重新解析该数据.您将不得不编写一些额外的代码来忽略多余的事件,因为这些事件会多次重新解析文件的开头.

An alternative would be to use NSURLConnection, and create a new NSXMLParser and re-parse the data each time some data comes in, in the connection:didReceiveData: method of your NSURLConnection's delegate. You''d have to write some extra code to ignore the extra events from re-parsing the beginning of the file more than once.

这似乎比抓取其他一些库并对其进行调整要花更多的精力,但也许不行,这取决于您如何处理表数据的下游创建.

This seems like it'd be more work than just grabbing some other library and adapting it, but maybe not, depending on how you're handling the downstream creation of your table data.

这篇关于iPhone网络性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆