Return-Path: Delivered-To: apmail-avro-commits-archive@www.apache.org Received: (qmail 54722 invoked from network); 14 Feb 2011 19:11:17 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 14 Feb 2011 19:11:17 -0000 Received: (qmail 38714 invoked by uid 500); 14 Feb 2011 19:11:16 -0000 Delivered-To: apmail-avro-commits-archive@avro.apache.org Received: (qmail 38678 invoked by uid 500); 14 Feb 2011 19:11:15 -0000 Mailing-List: contact commits-help@avro.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@avro.apache.org Delivered-To: mailing list commits@avro.apache.org Received: (qmail 38669 invoked by uid 99); 14 Feb 2011 19:11:14 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 14 Feb 2011 19:11:14 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 14 Feb 2011 19:11:13 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 52DDF2388A36; Mon, 14 Feb 2011 19:10:53 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1070613 - in /avro/trunk: CHANGES.txt lang/java/avro/src/main/java/org/apache/avro/io/BinaryDecoder.java Date: Mon, 14 Feb 2011 19:10:53 -0000 To: commits@avro.apache.org From: scottcarey@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110214191053.52DDF2388A36@eris.apache.org> Author: scottcarey Date: Mon Feb 14 19:10:52 2011 New Revision: 1070613 URL: http://svn.apache.org/viewvc?rev=1070613&view=rev Log: AVRO-765. Java: Improvement to BinaryDecoder readLong performance Modified: avro/trunk/CHANGES.txt avro/trunk/lang/java/avro/src/main/java/org/apache/avro/io/BinaryDecoder.java Modified: avro/trunk/CHANGES.txt URL: http://svn.apache.org/viewvc/avro/trunk/CHANGES.txt?rev=1070613&r1=1070612&r2=1070613&view=diff ============================================================================== --- avro/trunk/CHANGES.txt (original) +++ avro/trunk/CHANGES.txt Mon Feb 14 19:10:52 2011 @@ -90,6 +90,9 @@ Avro 1.5.0 (unreleased) IMPROVEMENTS + AVRO-765. Java: Improvement to BinaryDecoder readLong performance + (scottcarey) + AVRO-716. Java: integrate AVRO-647 changes with top level build (scottcarey) Modified: avro/trunk/lang/java/avro/src/main/java/org/apache/avro/io/BinaryDecoder.java URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/avro/src/main/java/org/apache/avro/io/BinaryDecoder.java?rev=1070613&r1=1070612&r2=1070613&view=diff ============================================================================== --- avro/trunk/lang/java/avro/src/main/java/org/apache/avro/io/BinaryDecoder.java (original) +++ avro/trunk/lang/java/avro/src/main/java/org/apache/avro/io/BinaryDecoder.java Mon Feb 14 19:10:52 2011 @@ -152,65 +152,41 @@ public class BinaryDecoder extends Decod if (b > 0x7f) { b = buf[pos + len++] & 0xff; n ^= (b & 0x7f) << 28; - } - if (b > 0x7f) { - throw new IOException("Invalid int encoding"); + if (b > 0x7f) { + throw new IOException("Invalid int encoding"); + } } } } } - if (pos + len > limit) { + pos += len; + if (pos > limit) { throw new EOFException(); } - pos += len; return (n >>> 1) ^ -(n & 1); // back to two's-complement } @Override public long readLong() throws IOException { ensureBounds(10); - int len = 1; - int b = buf[pos] & 0xff; + int b = buf[pos++] & 0xff; int n = b & 0x7f; long l; if (b > 0x7f) { - b = buf[pos + len++] & 0xff; + b = buf[pos++] & 0xff; n ^= (b & 0x7f) << 7; if (b > 0x7f) { - b = buf[pos + len++] & 0xff; + b = buf[pos++] & 0xff; n ^= (b & 0x7f) << 14; if (b > 0x7f) { - b = buf[pos + len++] & 0xff; + b = buf[pos++] & 0xff; n ^= (b & 0x7f) << 21; - // only the low 28 bits can be set, so this won't carry - // the sign bit to the long - l = n; if (b > 0x7f) { - b = buf[pos + len++] & 0xff; - l ^= (b & 0x7fL) << 28; - if (b > 0x7f) { - b = buf[pos + len++] & 0xff; - l ^= (b & 0x7fL) << 35; - if (b > 0x7f) { - b = buf[pos + len++] & 0xff; - l ^= (b & 0x7fL) << 42; - if (b > 0x7f) { - b = buf[pos + len++] & 0xff; - l ^= (b & 0x7fL) << 49; - if (b > 0x7f) { - b = buf[pos + len++] & 0xff; - l ^= (b & 0x7fL) << 56; - if (b > 0x7f) { - b = buf[pos + len++] & 0xff; - l ^= (b & 0x7fL) << 63; - } - if (b > 0x7f) { - throw new IOException("Invalid long encoding"); - } - } - } - } - } + // only the low 28 bits can be set, so this won't carry + // the sign bit to the long + l = innerLongDecode((long)n); + } else { + l = n; } } else { l = n; @@ -221,12 +197,44 @@ public class BinaryDecoder extends Decod } else { l = n; } - if (pos + len > limit) { + if (pos > limit) { throw new EOFException(); } - pos += len; return (l >>> 1) ^ -(l & 1); // back to two's-complement } + + // splitting readLong up makes it faster because of the JVM does more + // optimizations on small methods + private long innerLongDecode(long l) throws IOException { + int len = 1; + int b = buf[pos] & 0xff; + l ^= (b & 0x7fL) << 28; + if (b > 0x7f) { + b = buf[pos + len++] & 0xff; + l ^= (b & 0x7fL) << 35; + if (b > 0x7f) { + b = buf[pos + len++] & 0xff; + l ^= (b & 0x7fL) << 42; + if (b > 0x7f) { + b = buf[pos + len++] & 0xff; + l ^= (b & 0x7fL) << 49; + if (b > 0x7f) { + b = buf[pos + len++] & 0xff; + l ^= (b & 0x7fL) << 56; + if (b > 0x7f) { + b = buf[pos + len++] & 0xff; + l ^= (b & 0x7fL) << 63; + if (b > 0x7f) { + throw new IOException("Invalid long encoding"); + } + } + } + } + } + } + pos += len; + return l; + } @Override public float readFloat() throws IOException { @@ -261,11 +269,13 @@ public class BinaryDecoder extends Decod public Utf8 readString(Utf8 old) throws IOException { int length = readInt(); Utf8 result = (old != null ? old : new Utf8()); - result.setLength(length); - doReadBytes(result.getBytes(), 0, length); + result.setByteLength(length); + if (0 != length) { + doReadBytes(result.getBytes(), 0, length); + } return result; } - + @Override public void skipString() throws IOException { doSkipBytes(readInt());