Repository: tinkerpop
Updated Branches:
  refs/heads/TINKERPOP-1936 [created] 9370b49a3


TINKERPOP-1936 Improved performance of Bytecode deserialization.

GraphSON deserialization of Bytecode was using generic List deserialization 
which became especially costly for Jackson in 2.5.x because of changes that 
synchronized access to the deserialization cache and because the collection 
deserialization were no longer cacheable when type deserialization was in play. 
This change removed the use of generic type lists in deserialization and more 
directly handled the parsing of the lists thus bypassing the collection 
deserializer for this specific case.


Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/9370b49a
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/9370b49a
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/9370b49a

Branch: refs/heads/TINKERPOP-1936
Commit: 9370b49a3e04d719704f8b8fd52cc6f41d27ec98
Parents: 35bf95a
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Thu Apr 12 10:25:20 2018 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Thu Apr 12 10:25:20 2018 -0400

----------------------------------------------------------------------
 CHANGELOG.asciidoc                              |  5 +++
 .../io/graphson/TraversalSerializersV2d0.java   | 40 ++++++++++++++++----
 2 files changed, 37 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/9370b49a/CHANGELOG.asciidoc
----------------------------------------------------------------------
diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index 2b48a6f..b3d9cf7 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -20,6 +20,11 @@ limitations under the License.
 
 
image::https://raw.githubusercontent.com/apache/tinkerpop/master/docs/static/images/nine-inch-gremlins.png[width=185]
 
+[[release-3-2-9]]
+=== TinkerPop 3.2.9 (Release Date: NOT OFFICIALLY RELEASED YET)
+
+* Improved performance of GraphSON deserialization of `Bytecode`.
+
 [[release-3-2-8]]
 === TinkerPop 3.2.8 (Release Date: April 2, 2018)
 

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/9370b49a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/TraversalSerializersV2d0.java
----------------------------------------------------------------------
diff --git 
a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/TraversalSerializersV2d0.java
 
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/TraversalSerializersV2d0.java
index a696280..e6fa809 100644
--- 
a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/TraversalSerializersV2d0.java
+++ 
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/TraversalSerializersV2d0.java
@@ -248,8 +248,6 @@ final class TraversalSerializersV2d0 {
     //////////////////
 
     final static class BytecodeJacksonDeserializer extends 
StdDeserializer<Bytecode> {
-        private static final JavaType listJavaType = 
TypeFactory.defaultInstance().constructCollectionType(ArrayList.class, 
Object.class);
-        private static final JavaType listListJavaType = 
TypeFactory.defaultInstance().constructCollectionType(ArrayList.class, 
listJavaType);
 
         public BytecodeJacksonDeserializer() {
             super(Bytecode.class);
@@ -262,15 +260,41 @@ final class TraversalSerializersV2d0 {
             while (jsonParser.nextToken() != JsonToken.END_OBJECT) {
                 if (jsonParser.getCurrentName().equals(GraphSONTokens.SOURCE)) 
{
                     jsonParser.nextToken();
-                    final List<List<Object>> instructions = 
deserializationContext.readValue(jsonParser, listListJavaType);
-                    for (final List<Object> instruction : instructions) {
-                        bytecode.addSource((String) instruction.get(0), 
Arrays.copyOfRange(instruction.toArray(), 1, instruction.size()));
+
+                    // there should be a list now and the first item in the 
list is always string and is the step name
+                    // skip the start array
+                    jsonParser.nextToken();
+
+                    while (jsonParser.nextToken() != JsonToken.END_ARRAY) {
+                        final String stepName = jsonParser.getText();
+
+                        // iterate through the rest of the list for arguments 
until it gets to the end
+                        final List<Object> arguments = new ArrayList<>();
+                        while (jsonParser.nextToken() != JsonToken.END_ARRAY) {
+                            // we don't know the types here, so let the 
deserializer figure that business out
+                            
arguments.add(deserializationContext.readValue(jsonParser, Object.class));
+                        }
+
+                        bytecode.addSource(stepName, arguments.toArray());
                     }
                 } else if 
(jsonParser.getCurrentName().equals(GraphSONTokens.STEP)) {
                     jsonParser.nextToken();
-                    final List<List<Object>> instructions = 
deserializationContext.readValue(jsonParser, listListJavaType);
-                    for (final List<Object> instruction : instructions) {
-                        bytecode.addStep((String) instruction.get(0), 
Arrays.copyOfRange(instruction.toArray(), 1, instruction.size()));
+
+                    // there should be a list now and the first item in the 
list is always string and is the step name
+                    // skip the start array
+                    jsonParser.nextToken();
+
+                    while (jsonParser.nextToken() != JsonToken.END_ARRAY) {
+                        final String stepName = jsonParser.getText();
+
+                        // iterate through the rest of the list for arguments 
until it gets to the end
+                        final List<Object> arguments = new ArrayList<>();
+                        while (jsonParser.nextToken() != JsonToken.END_ARRAY) {
+                            // we don't know the types here, so let the 
deserializer figure that business out
+                            
arguments.add(deserializationContext.readValue(jsonParser, Object.class));
+                        }
+
+                        bytecode.addStep(stepName, arguments.toArray());
                     }
                 }
             }

Reply via email to