我正在以基本方式使用 Core Data 和 RestKit(只是默认的 RestKit 设置)。
有时,UI 会卡住很长时间(在 iPhone 5 上为 50 秒)。可以有很多对象,但没有什么特别的,对象很小(没有图像等)。
我怀疑这是由于某些上下文保存所致,但我不确定:我从来没有在我的应用程序中手动保存内容。
Instruments 的 Time Profiler 清楚地显示了卡住的地方,但我不明白输出,也不知道是什么原因造成的。最重的堆栈跟踪看起来像这样:
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]
有人能指出我正确的方向吗?
最佳答案
您是否尝试过在核心数据设置期间将托管对象缓存设置为 RKInMemoryManagedObjectCache
?我在 github 上看到这个问题后尝试了这个:https://github.com/RestKit/RestKit/issues/1232它显着加快了我的 restkit/核心数据基准测试。代码如下所示:
objectManager.managedObjectStore.managedObjectCache = [[RKInMemoryManagedObjectCache 分配] initWithManagedObjectContext: managedObjectStore.persistentStoreManagedObjectContext];
来自 http://restkit.org/api/0.20.0/Classes/RKInMemoryManagedObjectCache.html 的 RestKit 文档:“(RKInMemoryManagedObjectCache)提供了一个快速的托管对象缓存,其中对象实例保留在内存中以避免命中核心数据持久存储。性能大大提高了基于获取请求的策略,但以内存消耗为代价。”
关于ios - 核心数据 : performance issue. 仪器的输出是神秘的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23273527/