db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Matt Mastrangelo <mm...@ccs.neu.edu>
Subject Performance improvement in PersistenceBrokerImpl.getCollectionByQuery
Date Wed, 08 Jan 2003 18:51:12 GMT
In getCollectionByQuery in the PersistenceBrokerImpl class, the size of
the iterator is always calculated using iter.size().  However, in many
cases, this probably isnt necessary.  Unless a start at or end at index is
being used, the size of the iterator can be determined by the
retrievedCount integer which is incremented in the iteration loop.

By only calling iter.size() when there is a start at or end at index,
performance is significantly improved because an unnecessary count(*)
query to the database will often be prevented.  We have experienced a
noticeable improvement in our tests after making this change.

It could be implemented as follows:

/**
 * We only need to calculate the size if we are not going to loop through
 * the entire result set.  This is the case only when a start at or end at
 * index has been set.
 */
boolean mustCalculateSize = ((startAt != Query.NO_START_AT_INDEX) ||
(endAt != Query.NO_END_AT_INDEX));

if (mustCalculateSize)
{
/**
 * if the query has specified a start at index, and an end at index move
 * to the start at index.
 */
int size = iter.size();
/**
 * set full size of query to pass back to client.
 */
       query.fullSize(size);
}

And at the very end of the method

if (!mustCalculateSize)
{
query.fullSize(retrievedCount);
}

Let me know what you think.  Happy New Year!

Matt


Mime
View raw message