asterixdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wangs...@apache.org
Subject asterixdb git commit: ASTERIXDB-1746: no excessive new byte[] allocation during a record build
Date Tue, 06 Dec 2016 23:35:51 GMT
Repository: asterixdb
Updated Branches:
  refs/heads/master dc0cf73a5 -> 1170755c9


ASTERIXDB-1746: no excessive new byte[] allocation during a record build

 - During a record write using RecordBuilder.write(), it allocates two new byte[]
   using toByteArray() method. We can replace it to getByteArray() method and
   this reduces a lot of new byte[] allocation.

Change-Id: Ibdbc6314abd72d2a93978da49ea406c3c38731d2
Reviewed-on: https://asterix-gerrit.ics.uci.edu/1376
Sonar-Qube: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Ian Maxon <imaxon@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/asterixdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/asterixdb/commit/1170755c
Tree: http://git-wip-us.apache.org/repos/asf/asterixdb/tree/1170755c
Diff: http://git-wip-us.apache.org/repos/asf/asterixdb/diff/1170755c

Branch: refs/heads/master
Commit: 1170755c9d97f6552b2f2fee73687d0be1ee8670
Parents: dc0cf73
Author: Taewoo Kim <wangsaeu@yahoo.com>
Authored: Tue Dec 6 13:59:45 2016 -0800
Committer: Taewoo Kim <wangsaeu@yahoo.com>
Committed: Tue Dec 6 15:35:24 2016 -0800

----------------------------------------------------------------------
 .../java/org/apache/asterix/builders/RecordBuilder.java     | 9 ++++-----
 .../data/std/util/ByteArrayAccessibleOutputStream.java      | 7 +++++++
 2 files changed, 11 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/asterixdb/blob/1170755c/asterixdb/asterix-om/src/main/java/org/apache/asterix/builders/RecordBuilder.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/builders/RecordBuilder.java
b/asterixdb/asterix-om/src/main/java/org/apache/asterix/builders/RecordBuilder.java
index d247350..44181d5 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/builders/RecordBuilder.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/builders/RecordBuilder.java
@@ -20,7 +20,6 @@
 package org.apache.asterix.builders;
 
 import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
 import java.io.DataInputStream;
 import java.io.DataOutput;
 import java.io.IOException;
@@ -59,7 +58,7 @@ public class RecordBuilder implements IARecordBuilder {
     private final IBinaryHashFunction utf8HashFunction;
     private final IBinaryComparator utf8Comparator;
 
-    private final ByteArrayOutputStream closedPartOutputStream;
+    private final ByteArrayAccessibleOutputStream closedPartOutputStream;
     private int[] closedPartOffsets;
     private int numberOfClosedFields;
     private byte[] nullBitMap;
@@ -73,7 +72,7 @@ public class RecordBuilder implements IARecordBuilder {
     private RuntimeRecordTypeInfo recTypeInfo;
 
     public RecordBuilder() {
-        this.closedPartOutputStream = new ByteArrayOutputStream();
+        this.closedPartOutputStream = new ByteArrayAccessibleOutputStream();
         this.numberOfClosedFields = 0;
 
         this.openPartOutputStream = new ByteArrayAccessibleOutputStream();
@@ -287,14 +286,14 @@ public class RecordBuilder implements IARecordBuilder {
                 for (int i = 0; i < numberOfSchemaFields; i++) {
                     out.writeInt(closedPartOffsets[i] + headerSize + (numberOfSchemaFields
* 4));
                 }
-                out.write(closedPartOutputStream.toByteArray());
+                out.write(closedPartOutputStream.getByteArray(), 0, closedPartOutputStream.getLength());
             }
 
             // write the open part
             if (numberOfOpenFields > 0) {
                 out.writeInt(numberOfOpenFields);
                 out.write(openPartOffsetArray, 0, openPartOffsetArraySize);
-                out.write(openPartOutputStream.toByteArray());
+                out.write(openPartOutputStream.getByteArray(), 0, openPartOutputStream.getLength());
             }
         } catch (IOException e) {
             throw new HyracksDataException(e);

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/1170755c/hyracks-fullstack/hyracks/hyracks-data/hyracks-data-std/src/main/java/org/apache/hyracks/data/std/util/ByteArrayAccessibleOutputStream.java
----------------------------------------------------------------------
diff --git a/hyracks-fullstack/hyracks/hyracks-data/hyracks-data-std/src/main/java/org/apache/hyracks/data/std/util/ByteArrayAccessibleOutputStream.java
b/hyracks-fullstack/hyracks/hyracks-data/hyracks-data-std/src/main/java/org/apache/hyracks/data/std/util/ByteArrayAccessibleOutputStream.java
index 370f936..c1558ba 100644
--- a/hyracks-fullstack/hyracks/hyracks-data/hyracks-data-std/src/main/java/org/apache/hyracks/data/std/util/ByteArrayAccessibleOutputStream.java
+++ b/hyracks-fullstack/hyracks/hyracks-data/hyracks-data-std/src/main/java/org/apache/hyracks/data/std/util/ByteArrayAccessibleOutputStream.java
@@ -103,4 +103,11 @@ public class ByteArrayAccessibleOutputStream extends ByteArrayOutputStream
{
         }
         buf = Arrays.copyOf(buf, newCapacity);
     }
+
+    /**
+     * Return the current length of this stream (not capacity).
+     */
+    public int getLength() {
+        return count;
+    }
 }


Mime
View raw message