如何提高iPhone上Core Data对象插入的性能? [英] How do I improve performance of Core Data object insert on iPhone?

查看:116
本文介绍了如何提高iPhone上Core Data对象插入的性能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将大量数据导入iPhone上的核心数据存储。我使用SQLite支持核心数据存储。它似乎比我预期的时间长了。我已经修剪了例程,以便它基本上只是尝试获取一个对象(以查看它是否已经存在),然后创建一个新的对象,如果没有(他们从来没有,因为我导入数据)。提取不是耗时的部分,虽然。它是对象的创建。基本上,冒犯代码是:

I'm trying to import a large amount of data into a core data store on the iPhone. I'm using a SQLite backing for the core data store. It seems to be taking way longer than I would expect it to. I've trimmed down the routines so that it is basically just attempting to a fetch an object (to see if it already exists) and then create a new object if it doesn't (they never do since I am importing data). The fetching isn't the time consuming part, though. It's the creation of the objects. Basically, the offending code is:

MobileObject *newObject = (MobileObject *)[NSEntityDescription insertNewObjectForEntityForName:objDesc inManagedObjectContext:managedObjectContext];



我注意到,在模拟器上,它是相当快的开始与大约100个对象一秒。它减慢了,到时五千个对象被创建了几乎2秒的100个对象和时间创建万个对象,它是每100个对象4秒。整组21000个对象需要超过10分钟。这是所有的实际有用的代码被取出(这只是一个抓取和一个对象创建)。在实际设备上它慢得多(可能是4倍)。

I've noticed that on the simulator, it is fairly quick at the start with about 100 objects created a second. It slows down though and by the time five thousand objects are created it's almost 2 seconds for 100 objects and by the time ten thousand objects are created, it's 4 seconds per 100 objects. The whole group of 21000 objects takes more than 10 minutes. That is with all the actual useful code taken out (that's just a fetch and an object create). And it's much much slower on the actual device (by maybe 4 times as much).

我不明白为什么核心数据开始快,但开始减速。我已经尝试了索引和没有索引我的数据。我试着创建自己的autorelease池,我周期性地在我的循环。我已经尝试在每个对象创建后保存。我试着等到结束保存。但无论我做什么,表现仍然似乎悲惨。将一个新对象添加到具有几千个对象的核心数据存储中只是这么慢吗?任何建议?

What I don't understand is why core data starts off fast but then begins to slow down. I've tried both with index and no indexes on my data. I've tried creating my own autorelease pool which I periodically drain in my loop. I've tried saving after every object creation. I've tried waiting until the end to save. But no matter what I do, the performance still seems miserable. Is it just that slow to add a new object to a core data store with a few thousand objects in it? Any suggestions?

推荐答案

这可能相当迅速,但这取决于你在做什么。正如其他人建议你应该看仪器和找到实际的热点。发布实际的导入代码有助于识别问题。

It can be quite speedy but it depends on what you are doing. As others have suggested you should be looking at Instruments and finding the actual hotspot. Also posting the actual import code would help to identify the issue.

这篇关于如何提高iPhone上Core Data对象插入的性能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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