You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by sp...@apache.org on 2018/04/25 12:22:16 UTC

[1/4] tinkerpop git commit: TINKERPOP-1950 Cached global strategy lookups during traversal construction

Repository: tinkerpop
Updated Branches:
  refs/heads/master bd1dd084b -> 9aac0c933


TINKERPOP-1950 Cached global strategy lookups during traversal construction

This change leads to a 1.5x to 2x speed improvement in traversal construction. It is especially effective when processing traversals that have many child traversals within them as this method is called for not only the parent traversal but all the children as well.


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

Branch: refs/heads/master
Commit: cd20298d3f4ee5f66fe4f037e8aa64daf32254b4
Parents: 44c4073
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Fri Apr 20 16:18:13 2018 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Wed Apr 25 07:41:38 2018 -0400

----------------------------------------------------------------------
 CHANGELOG.asciidoc                              |  1 +
 .../process/traversal/TraversalStrategies.java  | 36 +++++++++++++++-----
 2 files changed, 29 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/cd20298d/CHANGELOG.asciidoc
----------------------------------------------------------------------
diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index f71602a..f6ca111 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -27,6 +27,7 @@ image::https://raw.githubusercontent.com/apache/tinkerpop/master/docs/static/ima
 * Bumped to httpclient 4.5.5.
 * Bumped to Groovy 2.4.15 - fixes bug with `Lambda` construction.
 * Improved performance of GraphSON deserialization of `Bytecode`.
+* Improved performance of traversal construction.
 
 [[release-3-2-8]]
 === TinkerPop 3.2.8 (Release Date: April 2, 2018)

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/cd20298d/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/TraversalStrategies.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/TraversalStrategies.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/TraversalStrategies.java
index c7ee5bf..e84737c 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/TraversalStrategies.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/TraversalStrategies.java
@@ -52,6 +52,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Optional;
 import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
 import java.util.stream.Collectors;
 
 /**
@@ -198,6 +199,12 @@ public interface TraversalStrategies extends Serializable, Cloneable {
 
     public static final class GlobalCache {
 
+        /**
+         * Keeps track of {@link GraphComputer} and/or {@link Graph} classes that have been initialized to the
+         * classloader so that they do not have to be reflected again.
+         */
+        private static Set<Class> LOADED = ConcurrentHashMap.newKeySet();
+
         private static final Map<Class<? extends Graph>, TraversalStrategies> GRAPH_CACHE = new HashMap<>();
         private static final Map<Class<? extends GraphComputer>, TraversalStrategies> GRAPH_COMPUTER_CACHE = new HashMap<>();
 
@@ -244,20 +251,33 @@ public interface TraversalStrategies extends Serializable, Cloneable {
         public static TraversalStrategies getStrategies(final Class graphOrGraphComputerClass) {
             try {
                 // be sure to load the class so that its static{} traversal strategy registration component is loaded.
-                // this is more important for GraphComputer classes as they are typically not instantiated prior to strategy usage like Graph classes.
-                final String graphComputerClassName = null != graphOrGraphComputerClass.getDeclaringClass() ?
+                // this is more important for GraphComputer classes as they are typically not instantiated prior to
+                // strategy usage like Graph classes.
+                if (!LOADED.contains(graphOrGraphComputerClass)) {
+                    final String graphComputerClassName = null != graphOrGraphComputerClass.getDeclaringClass() ?
                         graphOrGraphComputerClass.getCanonicalName().replace("." + graphOrGraphComputerClass.getSimpleName(), "$" + graphOrGraphComputerClass.getSimpleName()) :
                         graphOrGraphComputerClass.getCanonicalName();
-                Class.forName(graphComputerClassName);
+                    Class.forName(graphComputerClassName);
+
+                    // keep track of stuff we already loaded once - stuff in this if/statement isn't cheap and this
+                    // method gets called a lot, basically every time a new traversal gets spun up (that includes
+                    // child traversals. perhaps it is possible to just check the cache keys for this information, but
+                    // it's not clear if this method will be called with something not in the cache and if it is and
+                    // it results in error, then we'd probably not want to deal with this block again anyway
+                    LOADED.add(graphOrGraphComputerClass);
+                }
             } catch (final ClassNotFoundException e) {
                 throw new IllegalStateException(e.getMessage(), e);
             }
-            if (Graph.class.isAssignableFrom(graphOrGraphComputerClass)) {
-                final TraversalStrategies traversalStrategies = GRAPH_CACHE.get(graphOrGraphComputerClass);
-                return null == traversalStrategies ? GRAPH_CACHE.get(Graph.class) : traversalStrategies;
+            
+            if (GRAPH_CACHE.containsKey(graphOrGraphComputerClass)) {
+                return GRAPH_CACHE.get(graphOrGraphComputerClass);
+            } else if (Graph.class.isAssignableFrom(graphOrGraphComputerClass)) {
+                return GRAPH_CACHE.get(Graph.class);
+            } else if (GRAPH_COMPUTER_CACHE.containsKey(graphOrGraphComputerClass)) {
+                return GRAPH_COMPUTER_CACHE.get(graphOrGraphComputerClass);
             } else if (GraphComputer.class.isAssignableFrom(graphOrGraphComputerClass)) {
-                final TraversalStrategies traversalStrategies = GRAPH_COMPUTER_CACHE.get(graphOrGraphComputerClass);
-                return null == traversalStrategies ? GRAPH_COMPUTER_CACHE.get(GraphComputer.class) : traversalStrategies;
+                return GRAPH_COMPUTER_CACHE.get(GraphComputer.class);
             } else {
                 throw new IllegalArgumentException("The TraversalStrategies.GlobalCache only supports Graph and GraphComputer strategy caching: " + graphOrGraphComputerClass.getCanonicalName());
             }


[3/4] tinkerpop git commit: Merge branch 'tp32' into tp33

Posted by sp...@apache.org.
Merge branch 'tp32' into tp33


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

Branch: refs/heads/master
Commit: cfac56909777030f110474b97b62e06d3c343c93
Parents: b5b9e1a 0d6f8fc
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Wed Apr 25 08:21:57 2018 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Wed Apr 25 08:21:57 2018 -0400

----------------------------------------------------------------------
 CHANGELOG.asciidoc                              |  1 +
 .../process/traversal/TraversalStrategies.java  | 36 +++++++++++++++-----
 2 files changed, 29 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/cfac5690/CHANGELOG.asciidoc
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/cfac5690/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/TraversalStrategies.java
----------------------------------------------------------------------


[2/4] tinkerpop git commit: Merge branch 'TINKERPOP-1950' into tp32

Posted by sp...@apache.org.
Merge branch 'TINKERPOP-1950' into tp32


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

Branch: refs/heads/master
Commit: 0d6f8fcb208f850155fddbc1f140c1890a6757d7
Parents: f4dbaff cd20298
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Wed Apr 25 08:21:46 2018 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Wed Apr 25 08:21:46 2018 -0400

----------------------------------------------------------------------
 CHANGELOG.asciidoc                              |  1 +
 .../process/traversal/TraversalStrategies.java  | 36 +++++++++++++++-----
 2 files changed, 29 insertions(+), 8 deletions(-)
----------------------------------------------------------------------



[4/4] tinkerpop git commit: Merge branch 'tp33'

Posted by sp...@apache.org.
Merge branch 'tp33'


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

Branch: refs/heads/master
Commit: 9aac0c933ad6c0c46b49978b21d12ced6866761f
Parents: bd1dd08 cfac569
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Wed Apr 25 08:22:05 2018 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Wed Apr 25 08:22:05 2018 -0400

----------------------------------------------------------------------
 CHANGELOG.asciidoc                              |  1 +
 .../process/traversal/TraversalStrategies.java  | 36 +++++++++++++++-----
 2 files changed, 29 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/9aac0c93/CHANGELOG.asciidoc
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/9aac0c93/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/TraversalStrategies.java
----------------------------------------------------------------------