Return-Path: Mailing-List: contact ojb-dev-help@jakarta.apache.org; run by ezmlm Delivered-To: mailing list ojb-dev@jakarta.apache.org Received: (qmail 25378 invoked by uid 98); 8 Jan 2003 18:52:32 -0000 X-Antivirus: nagoya (v4218 created Aug 14 2002) Received: (qmail 25359 invoked from network); 8 Jan 2003 18:52:30 -0000 Received: from daedalus.apache.org (HELO apache.org) (63.251.56.142) by nagoya.betaversion.org with SMTP; 8 Jan 2003 18:52:30 -0000 Received: (qmail 42465 invoked by uid 500); 8 Jan 2003 18:51:09 -0000 Received: (qmail 42458 invoked from network); 8 Jan 2003 18:51:09 -0000 Received: from amber.ccs.neu.edu (129.10.116.51) by daedalus.apache.org with SMTP; 8 Jan 2003 18:51:09 -0000 Received: from denali.ccs.neu.edu (denali.ccs.neu.edu [129.10.116.200]) by amber.ccs.neu.edu (Postfix) with ESMTP id 600CE6B574 for ; Wed, 8 Jan 2003 13:51:12 -0500 (EST) Date: Wed, 8 Jan 2003 13:51:12 -0500 (EST) From: Matt Mastrangelo To: ojb-dev@jakarta.apache.org Subject: Performance improvement in PersistenceBrokerImpl.getCollectionByQuery Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N 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