Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id A1277B5DBE1 for ; Wed, 22 Jun 2011 00:27:22 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 40626-03 for ; Wed, 22 Jun 2011 03:27:16 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from www.postnewspapers.com.au (www.postnewspapers.com.au [173.230.139.50]) by mail.postgresql.org (Postfix) with ESMTP id 9895AB5D94C for ; Wed, 22 Jun 2011 00:27:16 -0300 (ADT) Received: from localhost (localhost [127.0.0.1]) by www.postnewspapers.com.au (Postfix) with ESMTP id 57E064B9; Tue, 21 Jun 2011 23:27:16 -0400 (EDT) X-Virus-Scanned: amavisd-new at postnewspapers.com.au.com Received: from www.postnewspapers.com.au ([127.0.0.1]) by localhost (www.postnewspapers.com.au [127.0.0.1]) (amavisd-new, port 10024) with LMTP id ISUmFSog2+Qw; Tue, 21 Jun 2011 23:27:15 -0400 (EDT) Received: from mail.postnewspapers.com.au (ppp171-128.static.internode.on.net [150.101.171.128]) by www.postnewspapers.com.au (Postfix) with ESMTP id 5DE3627; Tue, 21 Jun 2011 23:27:15 -0400 (EDT) Received: from [10.0.0.53] (wallace.localnet [10.0.0.53]) by mail.postnewspapers.com.au (Postfix) with ESMTP id 62082AE27D; Wed, 22 Jun 2011 11:27:14 +0800 (WST) Message-ID: <4E016112.3080709@postnewspapers.com.au> Date: Wed, 22 Jun 2011 11:27:14 +0800 From: Craig Ringer User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.15) Gecko/20110307 Thunderbird/3.1.9 MIME-Version: 1.0 To: Oliver Jowett CC: Andreas Schmitz , pgsql-jdbc@postgresql.org Subject: Re: bytea performance tweak References: <20110621130713.GB3919@summalogicae.occamlabs.local> In-Reply-To: X-Enigmail-Version: 1.1.2 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-10 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201106/48 X-Sequence-Number: 21972 On 22/06/11 07:59, Oliver Jowett wrote: > On 22 June 2011 01:08, Andreas Schmitz wrote: >> Hi, >> >> I've noticed that fetching a bytea field produces a lot of overhead when >> converting into a byte[] or InputStream. Looking at the code, I've >> produced a small patch (a lookup table for the hex codes) which makes >> the conversion faster. What do you think? > > Surprising. It's not at _all_ surprising that an array index lookup is much faster than two function calls and a bunch of branches. It'll probably JIT better and be easier on cache, too. If Oliver is lobbing around mostly bytea data and/or using big bytea fields I'm not surprised he's seeing this as at least somewhat of a hotspot. I've seen comments on bytea performance with JDBC here before, though nobody seems to have dug into it enough to track things down before. Thanks Oliver! -- Craig Ringer