Re: Some help with Optimization
Re: Some help with Optimization
- Subject: Re: Some help with Optimization
- From: Chuck Hill <email@hidden>
- Date: Thu, 9 Feb 2006 18:32:43 -0800
Hi Art,
On Feb 9, 2006, at 4:11 PM, Art Isbell wrote:
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.
I'll speculate this way will be faster, though not much in this
situation. It avoids a layer of KVC and also stops evaluation as
soon as it finds a match.
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);
=8-0 SHRIEK!
databaseContext.lock();
try {
databaseContext.batchFetchRelationship(defaultGroup.entityNamed
("External").relationshipNamed("activeName"), tempAllExs, ec);
selectableExtenals = (NSArray)tempAllExs.valueForKey("activeName");
}
finally {
databaseContext.unlock();
}
Yes, you need to. Really.
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.
Yep. That is probably the #1 cause of slow WO apps.
Chuck
--
Coming in 2006 - an introduction to web applications using WebObjects
and Xcode http://www.global-village.net/wointro
Practical WebObjects - for developers who want to increase their
overall knowledge of WebObjects or who are trying to solve specific
problems. http://www.global-village.net/products/practical_webobjects
_______________________________________________
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