简体   繁体   English

核心数据:性能问题。 仪器的输出是神秘的

[英]Core Data: performance issue. Instruments's output is cryptic

I am using Core Data and RestKit in a basic way (just the default RestKit setup). 我以一种基本方式使用Core Data和RestKit(只是默认的RestKit设置)。

From time to time, the UI gets stuck for a very long time (50s on an iPhone 5). 有时,UI会停留很长时间(在iPhone 5上为50秒钟)。 There can be quite a few objects, but nothing crazy and objects are small (no images etc). 可以有很多物体,但是没有疯狂的物体,物体很小(没有图像等)。

I suspect it is due to some context saving, but I am not sure: never in my app do I save things manually. 我怀疑这是由于保存了一些上下文而引起的,但是我不确定:我从来没有在应用程序中手动保存过东西。

Instruments' Time Profiler clearly shows what gets stuck, but I don't understand the output nor what's causing this. Instruments的Time Profiler清楚地显示出卡住了什么,但我既不了解输出也不知道是什么原因造成的。 The Heaviest Stack Trace looks like this: 最重的堆栈跟踪如下所示:

14  57129.0  Main Thread  0x4ea79 :0
13 CoreData 56680.0  -[NSManagedObjectContext(_NestedContextSupport) _parentObjectsForFetchRequest:inContext:error:]
12 CoreData 56523.0  -[NSManagedObjectContext executeFetchRequest:error:]
11 CoreData 56462.0  -[NSManagedObjectContext(_NestedContextSupport) executeRequest:withContext:error:]
10 CoreData 56442.0  -[NSManagedObjectContext(_NestedContextSupport) _parentObjectsForFetchRequest:inContext:error:]
 9 CoreData 56291.0  -[NSManagedObjectContext executeFetchRequest:error:]
 8 CoreData 50210.0  -[NSPersistentStoreCoordinator executeRequest:withContext:error:]
 7 CoreData 50193.0  -[NSMappedObjectStore executeFetchRequest:withContext:]
 6 CoreData 49978.0  -[NSDictionaryStoreMap handleFetchRequest:]
 5 Foundation 36516.0  -[NSPredicate evaluateWithObject:]
 4 Foundation 35865.0  -[NSComparisonPredicate evaluateWithObject:substitutionVariables:]
 3 Foundation 16845.0  -[NSFunctionExpression expressionValueWithObject:context:]
 2 CoreData 11823.0  -[NSDictionaryMapNode valueForKey:]
 1 CoreFoundation 1225.0  -[__NSCFString isEqualToString:]
 0 libobjc.A.dylib 36.0  -[NSObject class]

Can someone point me in the right direction? 有人可以指出我正确的方向吗?

Have you tried setting your managed object cache to RKInMemoryManagedObjectCache during core data setup? 您是否在核心数据设置期间尝试将托管对象缓存设置为RKInMemoryManagedObjectCache I tried this after seeing this issue on github: https://github.com/RestKit/RestKit/issues/1232 and it significantly sped up my restkit/core data benchmarks. 我在github上看到此问题后尝试了此操作: https : //github.com/RestKit/RestKit/issues/1232 ,它大大加快了我的restkit /核心数据基准测试速度。 Here is what the code looks like: 代码如下所示:

objectManager.managedObjectStore.managedObjectCache = [[RKInMemoryManagedObjectCache alloc] initWithManagedObjectContext: managedObjectStore.persistentStoreManagedObjectContext];

From the RestKit docs at http://restkit.org/api/0.20.0/Classes/RKInMemoryManagedObjectCache.html : "(RKInMemoryManagedObjectCache) Provides a fast managed object cache where-in object instances are retained in memory to avoid hitting the Core Data persistent store. Performance is greatly increased over fetch request based strategy at the expense of memory consumption." 来自http://restkit.org/api/0.20.0/Classes/RKInMemoryManagedObjectCache.html上的RestKit文档:“(RKInMemoryManagedObjectCache)提供了一个快速管理的对象缓存,其中将对象实例保留在内存中,以避免访问核心数据持久存储。与基于获取请求的策略相比,性能大大提高,但消耗了内存。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM