Taewoo Kim has uploaded a new change for review.

  https://asterix-gerrit.ics.uci.edu/1376

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

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
---
M 
asterixdb/asterix-om/src/main/java/org/apache/asterix/builders/RecordBuilder.java
M 
asterixdb/asterix-om/src/main/java/org/apache/asterix/om/pointables/cast/ARecordCaster.java
2 files changed, 6 insertions(+), 10 deletions(-)


  git pull ssh://asterix-gerrit.ics.uci.edu:29418/asterixdb 
refs/changes/76/1376/1

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..6664d73 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 @@
     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 @@
     private RuntimeRecordTypeInfo recTypeInfo;
 
     public RecordBuilder() {
-        this.closedPartOutputStream = new ByteArrayOutputStream();
+        this.closedPartOutputStream = new ByteArrayAccessibleOutputStream();
         this.numberOfClosedFields = 0;
 
         this.openPartOutputStream = new ByteArrayAccessibleOutputStream();
@@ -287,14 +286,14 @@
                 for (int i = 0; i < numberOfSchemaFields; i++) {
                     out.writeInt(closedPartOffsets[i] + headerSize + 
(numberOfSchemaFields * 4));
                 }
-                out.write(closedPartOutputStream.toByteArray());
+                out.write(closedPartOutputStream.getByteArray());
             }
 
             // write the open part
             if (numberOfOpenFields > 0) {
                 out.writeInt(numberOfOpenFields);
                 out.write(openPartOffsetArray, 0, openPartOffsetArraySize);
-                out.write(openPartOutputStream.toByteArray());
+                out.write(openPartOutputStream.getByteArray());
             }
         } catch (IOException e) {
             throw new HyracksDataException(e);
diff --git 
a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/pointables/cast/ARecordCaster.java
 
b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/pointables/cast/ARecordCaster.java
index 7e1fe46..d18b4d1 100644
--- 
a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/pointables/cast/ARecordCaster.java
+++ 
b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/pointables/cast/ARecordCaster.java
@@ -269,11 +269,8 @@
                         
.deserialize(fieldType.getByteArray()[fieldType.getStartOffset()]);
                 ps.print(typeTag);
 
-                //collect the output message
-                byte[] output = fieldBos.toByteArray();
-
-                //throw the exception
-                throw new IllegalStateException("type mismatch: including an 
extra field " + new String(output));
+                //collect the output message and throw the exception
+                throw new IllegalStateException("type mismatch: including an 
extra field " + fieldBos.toString());
             }
         }
 

-- 
To view, visit https://asterix-gerrit.ics.uci.edu/1376
To unsubscribe, visit https://asterix-gerrit.ics.uci.edu/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ibdbc6314abd72d2a93978da49ea406c3c38731d2
Gerrit-PatchSet: 1
Gerrit-Project: asterixdb
Gerrit-Branch: master
Gerrit-Owner: Taewoo Kim <[email protected]>

Reply via email to