ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [1/2] incubator-ignite git commit: ignite-950: performance improvements
Date Wed, 24 Jun 2015 11:01:17 GMT
Repository: incubator-ignite
Updated Branches:
  refs/heads/ignite-950 f632f1d95 -> 6bf4fa755


ignite-950: performance improvements


Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/0f97c471
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/0f97c471
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/0f97c471

Branch: refs/heads/ignite-950
Commit: 0f97c4714d912013641255c088494646dc79dfd8
Parents: f632f1d
Author: Denis Magda <dmagda@gridgain.com>
Authored: Wed Jun 24 13:11:26 2015 +0300
Committer: Denis Magda <dmagda@gridgain.com>
Committed: Wed Jun 24 13:11:26 2015 +0300

----------------------------------------------------------------------
 .../optimized/OptimizedObjectInputStream.java   | 84 ++++++++++++++------
 .../OptimizedObjectInputStreamExt.java          | 15 ++--
 .../optimized/OptimizedObjectOutputStream.java  | 64 +++++++++++----
 .../OptimizedObjectOutputStreamExt.java         | 59 +++++++++-----
 4 files changed, 155 insertions(+), 67 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0f97c471/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedObjectInputStream.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedObjectInputStream.java
b/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedObjectInputStream.java
index 2caf0cd..57f1a53 100644
--- a/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedObjectInputStream.java
+++ b/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedObjectInputStream.java
@@ -72,6 +72,9 @@ public class OptimizedObjectInputStream extends ObjectInputStream implements
Opt
     private Class<?> curCls;
 
     /** */
+    private boolean curHasFooter;
+
+    /** */
     private final HandleTable handles = new HandleTable(10);
 
     /** */
@@ -154,6 +157,7 @@ public class OptimizedObjectInputStream extends ObjectInputStream implements
Opt
 
         curObj = null;
         curFields = null;
+        curHasFooter = false;
         marshalAwareValues = null;
     }
 
@@ -161,6 +165,7 @@ public class OptimizedObjectInputStream extends ObjectInputStream implements
Opt
     @Override public Object readObjectOverride() throws ClassNotFoundException, IOException
{
         curObj = null;
         curFields = null;
+        curHasFooter = false;
 
         byte ref = in.readByte();
 
@@ -372,18 +377,22 @@ public class OptimizedObjectInputStream extends ObjectInputStream implements
Opt
      *
      * @param obj Object.
      * @param fieldOffs Field offsets.
+     * @param hasFooter Whether footer is included in the marshalled form.
      * @throws ClassNotFoundException If class not found.
      * @throws IOException In case of error.
      */
     @SuppressWarnings("ForLoopReplaceableByForEach")
-    void readFields(Object obj, OptimizedClassDescriptor.ClassFields fieldOffs) throws ClassNotFoundException,
+    void readFields(Object obj, OptimizedClassDescriptor.ClassFields fieldOffs, boolean hasFooter)
+        throws ClassNotFoundException,
         IOException {
+
         for (int i = 0; i < fieldOffs.size(); i++) {
             OptimizedClassDescriptor.FieldInfo t = fieldOffs.get(i);
 
             switch ((t.type())) {
                 case BYTE:
-                    readFieldType();
+                    if (hasFooter)
+                        readFieldType();
 
                     byte resByte = readByte();
 
@@ -393,7 +402,8 @@ public class OptimizedObjectInputStream extends ObjectInputStream implements
Opt
                     break;
 
                 case SHORT:
-                    readFieldType();
+                    if (hasFooter)
+                        readFieldType();
 
                     short resShort = readShort();
 
@@ -403,7 +413,8 @@ public class OptimizedObjectInputStream extends ObjectInputStream implements
Opt
                     break;
 
                 case INT:
-                    readFieldType();
+                    if (hasFooter)
+                        readFieldType();
 
                     int resInt = readInt();
 
@@ -413,7 +424,8 @@ public class OptimizedObjectInputStream extends ObjectInputStream implements
Opt
                     break;
 
                 case LONG:
-                    readFieldType();
+                    if (hasFooter)
+                        readFieldType();
 
                     long resLong = readLong();
 
@@ -423,7 +435,8 @@ public class OptimizedObjectInputStream extends ObjectInputStream implements
Opt
                     break;
 
                 case FLOAT:
-                    readFieldType();
+                    if (hasFooter)
+                        readFieldType();
 
                     float resFloat = readFloat();
 
@@ -433,7 +446,8 @@ public class OptimizedObjectInputStream extends ObjectInputStream implements
Opt
                     break;
 
                 case DOUBLE:
-                    readFieldType();
+                    if (hasFooter)
+                        readFieldType();
 
                     double resDouble = readDouble();
 
@@ -443,7 +457,8 @@ public class OptimizedObjectInputStream extends ObjectInputStream implements
Opt
                     break;
 
                 case CHAR:
-                    readFieldType();
+                    if (hasFooter)
+                        readFieldType();
 
                     char resChar = readChar();
 
@@ -453,7 +468,8 @@ public class OptimizedObjectInputStream extends ObjectInputStream implements
Opt
                     break;
 
                 case BOOLEAN:
-                    readFieldType();
+                    if (hasFooter)
+                        readFieldType();
 
                     boolean resBoolean = readBoolean();
 
@@ -656,7 +672,7 @@ public class OptimizedObjectInputStream extends ObjectInputStream implements
Opt
         if (marshalAwareValues.empty())
             marshalAwareValues = null;
 
-        skipFooter(obj.getClass());
+        skipFooter();
 
         return obj;
     }
@@ -686,12 +702,15 @@ public class OptimizedObjectInputStream extends ObjectInputStream implements
Opt
 
         int handle = handles.assign(obj);
 
+        boolean hasFooter = hasFooter(obj.getClass());
+
         for (int i = 0; i < mtds.size(); i++) {
             Method mtd = mtds.get(i);
 
             if (mtd != null) {
                 curObj = obj;
                 curFields = fields.fields(i);
+                curHasFooter = hasFooter;
 
                 try {
                     mtd.invoke(obj, this);
@@ -701,7 +720,7 @@ public class OptimizedObjectInputStream extends ObjectInputStream implements
Opt
                 }
             }
             else
-                readFields(obj, fields.fields(i));
+                readFields(obj, fields.fields(i), hasFooter);
         }
 
         if (readResolveMtd != null) {
@@ -715,7 +734,8 @@ public class OptimizedObjectInputStream extends ObjectInputStream implements
Opt
             }
         }
 
-        skipFooter(cls);
+        if (hasFooter)
+            skipFooter();
 
         return obj;
     }
@@ -1105,7 +1125,7 @@ public class OptimizedObjectInputStream extends ObjectInputStream implements
Opt
         if (curObj == null)
             throw new NotActiveException("Not in readObject() call.");
 
-        readFields(curObj, curFields);
+        readFields(curObj, curFields, curHasFooter);
     }
 
     /** {@inheritDoc} */
@@ -1248,12 +1268,22 @@ public class OptimizedObjectInputStream extends ObjectInputStream
implements Opt
     }
 
     /**
-     * Skips object footer from the underlying stream.
+     * Checks whether objects of the {@code cls} have footer.
      *
      * @param cls Class.
+     * @return {@code true} if has.
+     * @throws IOException In case of error.
+     */
+    protected boolean hasFooter(Class<?> cls) throws IOException {
+        return false;
+    }
+
+    /**
+     * Skips object footer from the underlying stream.
+     *
      * @throws IOException In case of error.
      */
-    protected void skipFooter(Class<?> cls) throws IOException {
+    protected void skipFooter() throws IOException {
         // No-op
     }
 
@@ -1563,56 +1593,64 @@ public class OptimizedObjectInputStream extends ObjectInputStream
implements Opt
 
                 switch (t.type()) {
                     case BYTE:
-                        in.readFieldType();
+                        if (in.curHasFooter)
+                            in.readFieldType();
 
                         obj = in.readByte();
 
                         break;
 
                     case SHORT:
-                        in.readFieldType();
+                        if (in.curHasFooter)
+                            in.readFieldType();
 
                         obj = in.readShort();
 
                         break;
 
                     case INT:
-                        in.readFieldType();
+                        if (in.curHasFooter)
+                            in.readFieldType();
 
                         obj = in.readInt();
 
                         break;
 
                     case LONG:
-                        in.readFieldType();
+                        if (in.curHasFooter)
+                            in.readFieldType();
 
                         obj = in.readLong();
 
                         break;
 
                     case FLOAT:
-                        in.readFieldType();
+                        if (in.curHasFooter)
+                            in.readFieldType();
 
                         obj = in.readFloat();
 
                         break;
 
                     case DOUBLE:
-                        in.readFieldType();
+                        if (in.curHasFooter)
+                            in.readFieldType();
 
                         obj = in.readDouble();
 
                         break;
 
                     case CHAR:
-                        in.readFieldType();
+                        if (in.curHasFooter)
+                            in.readFieldType();
 
                         obj = in.readChar();
 
                         break;
 
                     case BOOLEAN:
-                        in.readFieldType();
+                        if (in.curHasFooter)
+                            in.readFieldType();
 
                         obj = in.readBoolean();
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0f97c471/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedObjectInputStreamExt.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedObjectInputStreamExt.java
b/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedObjectInputStreamExt.java
index 622c19f..226ea20 100644
--- a/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedObjectInputStreamExt.java
+++ b/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedObjectInputStreamExt.java
@@ -33,13 +33,16 @@ public class OptimizedObjectInputStreamExt extends OptimizedObjectInputStream
{
     }
 
     /** {@inheritDoc} */
-    @Override protected void skipFooter(Class<?> cls) throws IOException {
-        if (fieldsIndexingSupported(cls, metaHandler, ctx, clsMap, mapper)) {
-            short footerLen = in.readShort();
+    @Override protected boolean hasFooter(Class<?> cls) throws IOException {
+        return fieldsIndexingSupported(cls, metaHandler, ctx, clsMap, mapper);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void skipFooter() throws IOException {
+        short footerLen = in.readShort();
 
-            if (footerLen != EMPTY_FOOTER)
-                in.skipBytes(footerLen - 2);
-        }
+        if (footerLen != EMPTY_FOOTER)
+            in.skipBytes(footerLen - 2);
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0f97c471/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedObjectOutputStream.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedObjectOutputStream.java
b/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedObjectOutputStream.java
index c8b24cc..2bb71e9 100644
--- a/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedObjectOutputStream.java
+++ b/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedObjectOutputStream.java
@@ -548,7 +548,9 @@ public class OptimizedObjectOutputStream extends ObjectOutputStream implements
O
             switch (t.type()) {
                 case BYTE:
                     if (t.field() != null) {
-                        writeFieldType(BYTE);
+                        if (footer != null)
+                            writeFieldType(BYTE);
+
                         writeByte(getByte(obj, t.offset()));
                     }
 
@@ -556,7 +558,9 @@ public class OptimizedObjectOutputStream extends ObjectOutputStream implements
O
 
                 case SHORT:
                     if (t.field() != null) {
-                        writeFieldType(SHORT);
+                        if (footer != null)
+                            writeFieldType(SHORT);
+
                         writeShort(getShort(obj, t.offset()));
                     }
 
@@ -564,7 +568,9 @@ public class OptimizedObjectOutputStream extends ObjectOutputStream implements
O
 
                 case INT:
                     if (t.field() != null) {
-                        writeFieldType(INT);
+                        if (footer != null)
+                            writeFieldType(INT);
+
                         writeInt(getInt(obj, t.offset()));
                     }
 
@@ -572,7 +578,9 @@ public class OptimizedObjectOutputStream extends ObjectOutputStream implements
O
 
                 case LONG:
                     if (t.field() != null) {
-                        writeFieldType(LONG);
+                        if (footer != null)
+                            writeFieldType(LONG);
+
                         writeLong(getLong(obj, t.offset()));
                     }
 
@@ -580,7 +588,9 @@ public class OptimizedObjectOutputStream extends ObjectOutputStream implements
O
 
                 case FLOAT:
                     if (t.field() != null) {
-                        writeFieldType(FLOAT);
+                        if (footer != null)
+                            writeFieldType(FLOAT);
+
                         writeFloat(getFloat(obj, t.offset()));
                     }
 
@@ -588,7 +598,9 @@ public class OptimizedObjectOutputStream extends ObjectOutputStream implements
O
 
                 case DOUBLE:
                     if (t.field() != null) {
-                        writeFieldType(DOUBLE);
+                        if (footer != null)
+                            writeFieldType(DOUBLE);
+
                         writeDouble(getDouble(obj, t.offset()));
                     }
 
@@ -596,7 +608,9 @@ public class OptimizedObjectOutputStream extends ObjectOutputStream implements
O
 
                 case CHAR:
                     if (t.field() != null) {
-                        writeFieldType(CHAR);
+                        if (footer != null)
+                            writeFieldType(CHAR);
+
                         writeChar(getChar(obj, t.offset()));
                     }
 
@@ -604,7 +618,9 @@ public class OptimizedObjectOutputStream extends ObjectOutputStream implements
O
 
                 case BOOLEAN:
                     if (t.field() != null) {
-                        writeFieldType(BOOLEAN);
+                        if (footer != null)
+                            writeFieldType(BOOLEAN);
+
                         writeBoolean(getBoolean(obj, t.offset()));
                     }
 
@@ -826,49 +842,65 @@ public class OptimizedObjectOutputStream extends ObjectOutputStream
implements O
 
             switch (t.get1().type()) {
                 case BYTE:
-                    writeFieldType(BYTE);
+                    if (footer != null)
+                        writeFieldType(BYTE);
+
                     writeByte((Byte)t.get2());
 
                     break;
 
                 case SHORT:
-                    writeFieldType(SHORT);
+                    if (footer != null)
+                        writeFieldType(SHORT);
+
                     writeShort((Short)t.get2());
 
                     break;
 
                 case INT:
-                    writeFieldType(INT);
+                    if (footer != null)
+                        writeFieldType(INT);
+
                     writeInt((Integer)t.get2());
 
                     break;
 
                 case LONG:
-                    writeFieldType(LONG);
+                    if (footer != null)
+                        writeFieldType(LONG);
+
                     writeLong((Long)t.get2());
 
                     break;
 
                 case FLOAT:
-                    writeFieldType(FLOAT);
+                    if (footer != null)
+                        writeFieldType(FLOAT);
+
                     writeFloat((Float)t.get2());
 
                     break;
 
                 case DOUBLE:
-                    writeFieldType(DOUBLE);
+                    if (footer != null)
+                        writeFieldType(DOUBLE);
+
                     writeDouble((Double)t.get2());
 
                     break;
 
                 case CHAR:
-                    writeFieldType(CHAR);
+                    if (footer != null)
+                        writeFieldType(CHAR);
+
                     writeChar((Character)t.get2());
 
                     break;
 
                 case BOOLEAN:
-                    writeFieldType(BOOLEAN);
+                    if (footer != null)
+                        writeFieldType(BOOLEAN);
+
                     writeBoolean((Boolean)t.get2());
 
                     break;

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/0f97c471/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedObjectOutputStreamExt.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedObjectOutputStreamExt.java
b/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedObjectOutputStreamExt.java
index 2be3165..2ded7c9 100644
--- a/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedObjectOutputStreamExt.java
+++ b/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/OptimizedObjectOutputStreamExt.java
@@ -41,11 +41,6 @@ public class OptimizedObjectOutputStreamExt extends OptimizedObjectOutputStream
     }
 
     /** {@inheritDoc} */
-    @Override protected void writeFieldType(byte type) throws IOException {
-        out.writeByte(type);
-    }
-
-    /** {@inheritDoc} */
     @Override protected Footer createFooter(Class<?> cls) {
         if (fieldsIndexingSupported(cls, metaHandler, ctx, clsMap, mapper))
             return new FooterImpl();
@@ -53,15 +48,17 @@ public class OptimizedObjectOutputStreamExt extends OptimizedObjectOutputStream
         return null;
     }
 
+    /** {@inheritDoc} */
+    @Override protected void writeFieldType(byte type) throws IOException {
+        out.writeByte(type);
+    }
+
     /**
      *
      */
     private class FooterImpl implements OptimizedObjectOutputStream.Footer {
         /** */
-        private ArrayList<Integer> data;
-
-        /** */
-        private ArrayList<Integer> fields;
+        private ArrayList<Meta> data;
 
         /** */
         private HashMap<Integer, GridHandleTable.ObjectInfo> handles;
@@ -71,10 +68,8 @@ public class OptimizedObjectOutputStreamExt extends OptimizedObjectOutputStream
 
         /** {@inheritDoc} */
         @Override public void indexingSupported(boolean indexingSupported) {
-            if (indexingSupported) {
+            if (indexingSupported)
                 data = new ArrayList<>();
-                this.fields = new ArrayList<>();
-            }
             else
                 data = null;
         }
@@ -84,10 +79,8 @@ public class OptimizedObjectOutputStreamExt extends OptimizedObjectOutputStream
             if (data == null)
                 return;
 
-            if (fieldType == OptimizedFieldType.OTHER) {
-                data.add(len);
-                fields.add(fieldId);
-            }
+            if (fieldType == OptimizedFieldType.OTHER)
+                data.add(new Meta(fieldId, len));
         }
 
         /** {@inheritDoc} */
@@ -109,7 +102,7 @@ public class OptimizedObjectOutputStreamExt extends OptimizedObjectOutputStream
         /** {@inheritDoc} */
         @Override public void write() throws IOException {
             if (data == null)
-                writeInt(EMPTY_FOOTER);
+                writeShort(EMPTY_FOOTER);
             else {
                 int bodyEnd = out.offset();
 
@@ -123,12 +116,14 @@ public class OptimizedObjectOutputStreamExt extends OptimizedObjectOutputStream
 
                 if (hasHandles) {
                     for (int i = 0; i < data.size(); i++) {
-                        GridHandleTable.ObjectInfo objInfo = handles.get(fields.get(i));
+                        Meta fieldMeta = data.get(i);
+
+                        GridHandleTable.ObjectInfo objInfo = handles.get(fieldMeta.fieldId);
 
                         if (objInfo == null)
-                            writeInt(data.get(i) & ~FOOTER_BODY_IS_HANDLE_MASK);
+                            writeInt(fieldMeta.fieldLen & ~FOOTER_BODY_IS_HANDLE_MASK);
                         else {
-                            writeInt(data.get(i) | FOOTER_BODY_IS_HANDLE_MASK);
+                            writeInt(fieldMeta.fieldLen | FOOTER_BODY_IS_HANDLE_MASK);
                             writeInt(objInfo.position());
 
                             if (objInfo.length() == 0)
@@ -140,12 +135,32 @@ public class OptimizedObjectOutputStreamExt extends OptimizedObjectOutputStream
                     }
                 }
                 else
-                    for (int fieldLen : data)
+                    for (Meta fieldMeta : data)
                         // writing field len and resetting is handle mask
-                        writeInt(fieldLen & ~FOOTER_BODY_IS_HANDLE_MASK);
+                        writeInt(fieldMeta.fieldLen & ~FOOTER_BODY_IS_HANDLE_MASK);
 
                 writeShort(footerLen);
             }
         }
     }
+
+    /**
+     *
+     */
+    private static class Meta {
+        /** */
+        int fieldId;
+
+        /** */
+        int fieldLen;
+
+        /**
+         * @param fieldId
+         * @param fieldLen
+         */
+        public Meta(int fieldId, int fieldLen) {
+            this.fieldId = fieldId;
+            this.fieldLen = fieldLen;
+        }
+    }
 }


Mime
View raw message