RestKit performance is unacceptably slow when downloading just shy of 9,000 objects — it's taking 10 minutes on the simulator, and indefinite time on an iPad Mini.
I have several tables I'm downloading from a restful interface. It all works, but there appears to be an exponential scale problem that becomes intolerable when there are many objects. The following table has the most problems:
optionMapping.identificationAttributes = @[@"optionID"];
// OptionType
RKEntityMapping *optionTypeMapping = [RKEntityMapping mappingForEntityForName:@"OptionType" inManagedObjectStore:rkMOS];
[optionTypeMapping addAttributeMappingsFromDictionary:@{
@"id" : @"optionTypeID",
@"option_type" : @"optionType",}];
optionTypeMapping.identificationAttributes = @[@"optionTypeID"];
The attribute optionTypeID is indexed in Core Data, and is not optional.
There are some relationships to other tables, which I map as follows:
// Option.optionType -> OptionType
[optionMapping addConnectionForRelationship:@"optionType" connectedBy: @"optionTypeID"];
// Option.unit -> Unit
[optionMapping addConnectionForRelationship:@"unit" connectedBy:@"unitID"];
These don't seem to be the problem -- I commented them out, and the download is still very, very slow.
I set up a response descriptor (this is a catalog, so I only need to download it). Note that the following code shows a setup for all of the tables.
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];
I'm using the object manager to download the table:
[_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];
}
}];
The console output shows that mapping is chugging along, but it takes forever. The following is just one snippet from thousands like it:
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]
Any ideas on how I can speed this up? All I want to do is blast the data down from the server to Core Data.