Re: Some help with Optimization
Re: Some help with Optimization
- Subject: Re: Some help with Optimization
- From: Owen McKerrow <email@hidden>
- Date: Fri, 10 Feb 2006 11:35:05 +1100
Hi all,
See below .....
On 10/02/2006, at 11:11 AM, 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 actually changed the above function for some testing to just always
return (PersonName)personNames().objectAtIndex(0) i.e. the first
name, no matter if its active or not, and added a System.out.println
(new NSTimestamp()) as the first line. What I found happen was that
the first object would be asked for its active name, the fault would
fire, the 1888 objects would be retrieved from the database and then
the next object would ask for its activeName. So between the first
and second call to activeName() there was a 10 sec gap when it was
getting stuff from the database. So it seems to be the DB transaction
and making the results into EO entities. Which is very strange cause
the call before to just get the external members which also return
1800 odd object takes 2 seconds.
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");
Unfortunately this won't work as activeName() isn't a real
relationship, its a function. I may have to go back and add this
relationship.
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.
PersonName is set up with a unique index on _rowid, a clustered index
on active and a normal index on lastName. Would you suggest changing
this to say index on personID ?
Thanks
Owen
_______________________________________________
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