Return-Path: Delivered-To: apmail-db-derby-dev-archive@www.apache.org Received: (qmail 70541 invoked from network); 24 Nov 2006 10:24:07 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 24 Nov 2006 10:24:07 -0000 Received: (qmail 86816 invoked by uid 500); 24 Nov 2006 10:24:17 -0000 Delivered-To: apmail-db-derby-dev-archive@db.apache.org Received: (qmail 86624 invoked by uid 500); 24 Nov 2006 10:24:16 -0000 Mailing-List: contact derby-dev-help@db.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: Delivered-To: mailing list derby-dev@db.apache.org Received: (qmail 86615 invoked by uid 99); 24 Nov 2006 10:24:16 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 24 Nov 2006 02:24:16 -0800 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests=UNPARSEABLE_RELAY X-Spam-Check-By: apache.org Received-SPF: pass (herse.apache.org: local policy) Received: from [192.18.1.36] (HELO gmp-ea-fw-1.sun.com) (192.18.1.36) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 24 Nov 2006 02:24:02 -0800 Received: from d1-emea-09.sun.com (d1-emea-09.sun.com [192.18.2.119]) by gmp-ea-fw-1.sun.com (8.13.6+Sun/8.12.9) with ESMTP id kAOANdtv008556 for ; Fri, 24 Nov 2006 10:23:41 GMT Received: from conversion-daemon.d1-emea-09.sun.com by d1-emea-09.sun.com (Sun Java System Messaging Server 6.2-6.01 (built Apr 3 2006)) id <0J9800G01CR2ME00@d1-emea-09.sun.com> (original mail from Knut.Hatlen@Sun.COM) for derby-dev@db.apache.org; Fri, 24 Nov 2006 10:23:39 +0000 (GMT) Received: from localhost ([129.159.112.231]) by d1-emea-09.sun.com (Sun Java System Messaging Server 6.2-6.01 (built Apr 3 2006)) with ESMTPSA id <0J9800MRPCVE0JF6@d1-emea-09.sun.com> for derby-dev@db.apache.org; Fri, 24 Nov 2006 10:23:39 +0000 (GMT) Date: Fri, 24 Nov 2006 11:23:37 +0100 From: Knut Anders Hatlen Subject: Re: ArrayInputStream and performance In-reply-to: Sender: Knut.Hatlen@Sun.COM To: derby-dev@db.apache.org Message-id: Organization: Sun Microsystems MIME-version: 1.0 Content-type: text/plain; charset=us-ascii Content-transfer-encoding: 7BIT References: User-Agent: Gnus/5.110006 (No Gnus v0.6) Emacs/22.0.91 (usg-unix-v) X-Virus-Checked: Checked by ClamAV on apache.org Dyre.Tjeldvoll@Sun.COM writes: > I have noticed that two methods, setPosition(int) and setLimit(int) > seem to use more CPU than what I find "reasonable" given what they're > supposed to do. Together they use 4.5% of user CPU and 1.5% of system > CPU. > > Looking closer at what each method does, it seems like a fair amount > of the CPU is on argument/consistency checking. > > For setPosition(int) it seems simple to replace the checking with > an ASSERT, but in setLimit(int) a failed check will cause 'start', 'end' > and 'position' to be set to 0 before an exception is thrown: > > start = position; > end = position + length; > > if (end <= pageData.length) > { > return; > } > else > { > start = end = position = 0; > throw new EOFException(); > } > > Does anybody know if there is code that catches this exception and > that relies on these variables being set to 0? I can't answer your question, but I will add that I find much of the code that uses ArrayInputStream very confusing. ArrayInputStream is supposed to wrap a byte array to provide encapsulation and easy access to the data through the InputStream interface. However, many (most?) of the callers inline the accesses to the data (presumably for performance reasons), so we end up with lots of methods looking like this: public X readSomething(ArrayInputStream ais, byte[] data, int offset...) { // lots of direct manipulation of the byte array // ... // ... // ... // finally, make sure that the state of the stream is brought to a // consistent state: ais.setPosition(offset + numberOfManipulatedBytes); } Both the byte array and the offset are part of the ArrayInputStream class, so having all three of them in the parameter list feels a bit ugly. And if we need to manipulate the internal state directly that often, perhaps an InputStream is not the best data structure in the first place? -- Knut Anders