2013-08-01 58 views
15

仅仅下载9000个对象时,RestKit的性能非常慢,它在模拟器上需要10分钟,而在iPad Mini上需要不确定的时间。RestKit性能和核心数据

我有几个表我从一个宁静的界面下载。这一切都有效,但似乎有一个指数级的规模问题,当有许多对象时,这个问题变得不可容忍。下面的表中有最多的问题:

optionMapping.identificationAttributes = @[@"optionID"]; 

// OptionType 
RKEntityMapping *optionTypeMapping = [RKEntityMapping mappingForEntityForName:@"OptionType" inManagedObjectStore:rkMOS]; 
[optionTypeMapping addAttributeMappingsFromDictionary:@{ 
@"id" : @"optionTypeID", 
@"option_type" : @"optionType",}]; 

optionTypeMapping.identificationAttributes = @[@"optionTypeID"]; 

属性optionTypeID在核心数据索引,而不是可有可无的。

还有其他表,这是我的一些映射关系如下:

// Option.optionType -> OptionType 

[optionMapping addConnectionForRelationship:@"optionType" connectedBy: @"optionTypeID"]; 

// Option.unit -> Unit 

[optionMapping addConnectionForRelationship:@"unit" connectedBy:@"unitID"]; 

这些似乎并不成为问题 - 我评论他们,并在下载还是非常非常慢。

我设置了一个响应描述符(这是一个目录,所以我只需要下载它)。请注意,以下代码显示了所有表的设置。

NSArray *reqA = @[@{@"endpoint" : API_VENDORS_ENDPOINT, 
        @"mapping" : vendorMapping}, 

        @{@"endpoint" : API_OPTION_TYPES_ENDPOINT, 
        @"mapping" : optionTypeMapping}, 

        @{@"endpoint" : API_OPTIONS_ENDPOINT, 
        @"mapping" : optionMapping}, 

        @{@"endpoint" : API_UNITS_ENDPOINT, 
        @"mapping" : unitMapping}, 

        @{@"endpoint" : API_PRICE_TIERS_ENDPOINT, 
        @"mapping" : priceTierMapping}, 

        @{@"endpoint" : API_PRODUCT_TYPES_ENDPOINT, 
        @"mapping" : productTypeMapping}, 

        @{@"endpoint" : API_PRODUCTS_ENDPOINT, 
        @"mapping" : productMapping} 
        ]; 

for (NSDictionary *mapD in reqA) { 

    RKResponseDescriptor *thisRD = [RKResponseDescriptor 
            responseDescriptorWithMapping:[mapD valueForKey:@"mapping"] 
            pathPattern:[mapD valueForKey:@"endpoint"] 
            keyPath:nil 
            statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)]; 

    [_objMgr addResponseDescriptor:thisRD]; 

我使用对象管理器下载表格:

[_objMgr getObjectsAtPath:verbStr 
       parameters:nil 
       success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) { 
        RKLogInfo(@"%@ load complete: %@", verbStr, [NSDate date]); 

        NSInteger idx = [loadA indexOfObject:verbStr] + 1; 

        if (idx < [loadA count]) { 
         [self load:[loadA objectAtIndex:idx] stack:loadA]; 
        } 

        [[NSUserDefaults standardUserDefaults] setObject:[NSDate date] forKey:verbStr]; 
        [[NSUserDefaults standardUserDefaults] synchronize]; 

        NSDictionary *options = @{@"verb" : verbStr}; 
        [[NSNotificationCenter defaultCenter] postNotificationName:OBJECTS_DOWNLOADED object:self userInfo:options]; 

       } failure:^(RKObjectRequestOperation *operation, NSError *error) { 
        RKLogError(@"Load failed with error: %@", error); 

        NSInteger statusCode = operation.HTTPRequestOperation.response.statusCode; 

        if (401 == statusCode) { 
         [self resetAdmin]; 
        } 
       }]; 

控制台输出显示映射车轮继续滚滚向前,但它永远。以下仅为千篇一个片段之一:

2013-08-01 17:11:49.319 CarpetDirect[138:1507] D restkit.object_mapping:RKMappingOperation.m:952 Starting mapping operation... 
2013-08-01 17:11:49.321 CarpetDirect[138:1507] T restkit.object_mapping:RKMappingOperation.m:953 Performing mapping operation: <RKMappingOperation 0x1dda2160> for 'Option' object. Mapping values from object { 
    id = 1307; 
    "option_type" = 0; 
    unit = "<null>"; 
    value = "939 Puddle"; 
} to object <Option: 0x1dd55020> (entity: Option; id: 0x1dd55060 <x-coredata:///Option/t3ABD9C1C-1BBA-4C39-AEF7-EB3D1D9AFC0B1334> ; data: { 
    optionID = 1307; 
    optionType = nil; 
    optionTypeID = 0; 
    orderedItems =  (
); 
    products =  (
); 
    unit = nil; 
    unitID = 0; 
    value = nil; 
}) with object mapping (null) 
2013-08-01 17:11:49.324 CarpetDirect[138:1507] T restkit.object_mapping:RKMappingOperation.m:550 Mapping attribute value keyPath 'id' to 'optionID' 
2013-08-01 17:11:49.326 CarpetDirect[138:1507] T restkit.object_mapping:RKMappingOperation.m:583 Skipped mapping of attribute value from keyPath 'id to keyPath 'optionID' -- value is unchanged (1307) 
2013-08-01 17:11:49.329 CarpetDirect[138:1507] T restkit.object_mapping:RKMappingOperation.m:550 Mapping attribute value keyPath 'unit' to 'unitID' 
2013-08-01 17:11:49.333 CarpetDirect[138:1507] T restkit.object_mapping:RKMappingOperation.m:431 Found transformable value at keyPath 'unit'. Transforming from type 'NSNull' to 'NSNumber' 
2013-08-01 17:11:49.334 CarpetDirect[138:1507] T restkit.object_mapping:RKMappingOperation.m:572 Mapped attribute value from keyPath 'unit' to 'unitID'. Value: (null) 
2013-08-01 17:11:49.336 CarpetDirect[138:1507] T restkit.object_mapping:RKMappingOperation.m:550 Mapping attribute value keyPath 'value' to 'value' 
2013-08-01 17:11:49.338 CarpetDirect[138:1507] T restkit.object_mapping:RKMappingOperation.m:572 Mapped attribute value from keyPath 'value' to 'value'. Value: 939 Puddle 
2013-08-01 17:11:49.339 CarpetDirect[138:1507] T restkit.object_mapping:RKMappingOperation.m:550 Mapping attribute value keyPath 'option_type' to 'optionTypeID' 
2013-08-01 17:11:49.342 CarpetDirect[138:1507] T restkit.object_mapping:RKMappingOperation.m:583 Skipped mapping of attribute value from keyPath 'option_type to keyPath 'optionTypeID' -- value is unchanged (0) 
2013-08-01 17:11:49.345 CarpetDirect[138:1507] D restkit.object_mapping:RKMappingOperation.m:1021 Finished mapping operation successfully... 
2013-08-01 17:11:49.348 CarpetDirect[138:1507] 

关于如何加快速度的任何想法?我想要做的就是将数据从服务器上传送到Core Data。

+0

这些是9000个独立的请求吗?如果是这样,那么每分钟900,每秒15,可能不会更快。 – Thilo

+1

这一切都在服务器的请求。 json快速回来,所以这不是问题。问题是RestKit将数据倒入核心数据所花费的时间。 – user2379765

+0

我搞砸了第一个代码片段。它应该是:RKEntityMapping * optionMapping = [RKEntityMapping mappingForEntityForName:@“Option”inManagedObjectStore:rkMOS]; [optionMapping addAttributeMappingsFromDictionary:@ { @ “ID”:@ “optionID”, @ “option_type”:@ “optionTypeID”, @ “单元”:@ “的UnitID”, @ “值”:@ “值” }]; optionMapping.identificationAttributes = @ [@“optionID”]; – user2379765

回答

2

很难说没有更多的上下文,但什么是您的RestKit日志记录选项?根据我的经验,在RestKit中映射日志非常冗长,使事情减慢了10倍。

禁用所有RestKit日志记录,并查看是否有任何改进。然后,如果仍有问题,请使用Instruments来分析您的应用程序 - 您应该很容易地看到哪些代码路径大部分时间都用完了(解析,RestKit映射,核心数据等)。

+1

在性能方面,记录确实是RestKit的一个问题。好的提示! – magma