Re: Some help with Optimization
Re: Some help with Optimization
- Subject: Re: Some help with Optimization
- From: Art Isbell <email@hidden>
- Date: Thu, 9 Feb 2006 14:11:28 -1000
On Feb 9, 2006, at 1:00 PM, Owen McKerrow wrote:
public PersonName activeName()
{
int i;
PersonName theName= null;
for (i=0;i<personNames().count();i++) {
PersonName temp = (PersonName)personNames().objectAtIndex(i);
if ( temp.active().intValue() == 1 ) {
theName = temp;
break;
}
}
return theName;
}
Is there an easier/quicker way to do this ?
Rather than iterate through personNames, I would typically filter
personNames using a qualifier that tests for active equals new Integer
(1). I have no idea which approach, on average, would be faster.
System.out.println("Get Authors :" + new NSTimestamp());
NSArray tempAllExs = (NSArray)
EOUtilities.objectsWithFetchSpecificationAndBindings
(ec,"External","allMembers",new NSMutableDictionary());
System.out.println("Get names via value for key :" + new NSTimestamp
());
selectableExtenals = (NSArray)tempAllExs.valueForKey("activeName");
System.out.println("End :" + new NSTimestamp());
Which results in :
Get Authors :2006-02-09 21:50:46 Etc/GMT
Get names via value for key :2006-02-09 21:50:47 Etc/GMT
End :2006-02-09 21:50:57 Etc/GMT
As you can see there's 10 seconds to do the valueForKey bit.
Turning on SQL logging and I find that when I do the valuforKey
look up its going back to the DB to get all the names.
I typically batch fetch rather than batch fault:
NSArray tempAllExs =
EOUtilities.objectsWithFetchSpecificationAndBindings(ec, "External",
"allMembers", NSDictionary.EmptyDictionary);
EOModelGroup defaultGroup = EOModelGroup.defaultGroup();
EODatabaseContext databaseContext =
EODatabaseContext.registeredDatabaseContextForModel
(defaultGroup.modelNamed("ModelName"), ec);
databaseContext.batchFetchRelationship(defaultGroup.entityNamed
("External").relationshipNamed("activeName"), tempAllExs, ec);
selectableExtenals = (NSArray)tempAllExs.valueForKey("activeName");
Anyways 10 seconds still seems like a long time even if it does
need to get the info from the DB.
I have no idea whether my suggestions will accelerate your app, but
they'd be worth a quick try. Also, you should ensure that the DB
columns involved are indexed.
Aloha,
Art
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden