Re: Is NSEntityDescription insertNewObjectForEntityForName:inManagedObjectContext: this slow?
Re: Is NSEntityDescription insertNewObjectForEntityForName:inManagedObjectContext: this slow?
- Subject: Re: Is NSEntityDescription insertNewObjectForEntityForName:inManagedObjectContext: this slow?
- From: mmalcolm crawford <email@hidden>
- Date: Fri, 15 Jul 2005 01:56:29 -0700
On Jul 15, 2005, at 1:30 AM, Javigator wrote:
At some point in the application there's some data generation which
initially is in the form of nested NSArrays. Top level array
consists of around 600 NSArray objects, all of them containing 11
objects (they correspond to the attributes of Entity1). The goal is
to convert this into CoreData entities to be stored and displayed
in a table.
My current implementation looks simple and is working: Loop over
those 600 objects, create an entity using NSEntityDescription
insertNewObjectForEntityForName:inManagedObjectContext: and fill in
the data using setValue:forKey: for each of the attributes of the
entity. Additionally set the relationship to the currently selected
Entity2 object.
But on my PowerMac G5 1,8 SP (1st gen.) with 1,5 GB this conversion
takes over 30 seconds - and that's without saving the data store!
I'm really stunned because of this bad performance... I was
thinking that the object creation shouldn't take more than one to
three seconds.
A rather trivial test using two orders of magnitude the number of
objects you state takes about 10 seconds on a 1.5MHz PowerBook. I
suspect the problem lies elsewhere...
mmalc
[Entity1 has 12 attributes each with a default value set in the model.]
int i;
NSManagedObject *mo, *mo2;
NSManagedObjectContext *context = [self managedObjectContext];
mo2 = [NSEntityDescription
insertNewObjectForEntityForName:@"Entity2"
inManagedObjectContext:context];
NSLog(@"Date: %@", [NSDate date]);
for (i = 0; i < 60000; i++) {
mo = [NSEntityDescription
insertNewObjectForEntityForName:@"Entity"
inManagedObjectContext:context];
NSMutableSet *relationship = [mo2
mutableSetValueForKey:@"newRelationship"];
[relationship addObject:mo];
}
NSLog(@"Date: %@", [NSDate date]);
Date: 2005-07-15 01:52:09 -0700
Date: 2005-07-15 01:52:20 -0700
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden