ios - 核心数据 : performance issue. 仪器的输出是神秘的

标签 ios core-data restkit

我正在以基本方式使用 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/

相关文章:

ios - 如何计算/遍历 NSManagedObject 具有的所有属性?

iphone - ResKit iOS - 为同一个元素注册多个类

ios - RESKit : Duplicate objects are created

ios - Core Data 第一次没有保存

ios - UILocalNotification 后台事件触发以暂停 iOS 中的音乐

ios - Swift Regular Expression create For Url "www"not for "http"for valid URL

ios - 将键值函数与 NSExpression 结合起来

objective-c - `ordered` 标志在一对多关系中的作用是什么?

iphone - UINavigationBar 标题在使用自定义字体时被截断

ios - 使用 AutoLayout 仅旋转 View