tinkerpop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From twil...@apache.org
Subject [7/8] incubator-tinkerpop git commit: TINKERPOP3-957 Made a number of changes to improve traversal startup and execution performance.
Date Mon, 16 Nov 2015 15:23:05 GMT
TINKERPOP3-957 Made a number of changes to improve traversal startup and execution performance.


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

Branch: refs/heads/TINKERPOP3-957
Commit: 42e771d7073161208f1908ab7c0f9303a8effa53
Parents: 47e531a
Author: Ted Wilmes <twilmes@gmail.com>
Authored: Mon Nov 16 08:39:46 2015 -0600
Committer: Ted Wilmes <twilmes@gmail.com>
Committed: Mon Nov 16 09:16:58 2015 -0600

----------------------------------------------------------------------
 .../process/traversal/step/util/Parameters.java      | 15 +++++++++++----
 .../finalization/EngineDependentStrategy.java        |  8 +++++---
 .../process/traversal/util/DefaultTraversal.java     | 13 +++++++++----
 .../traversal/util/DefaultTraversalStrategies.java   |  2 +-
 .../process/traversal/util/TraversalHelper.java      |  8 +++++++-
 5 files changed, 33 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/42e771d7/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/Parameters.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/Parameters.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/Parameters.java
index b99d8de..f98e616 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/Parameters.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/Parameters.java
@@ -19,6 +19,7 @@
 
 package org.apache.tinkerpop.gremlin.process.traversal.step.util;
 
+import org.apache.commons.lang.ArrayUtils;
 import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
 import org.apache.tinkerpop.gremlin.process.traversal.Traverser;
 import org.apache.tinkerpop.gremlin.process.traversal.step.TraversalParent;
@@ -32,7 +33,6 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.function.Supplier;
-import java.util.stream.Collectors;
 
 /**
  * The parameters held by a {@link Traversal}.
@@ -100,10 +100,9 @@ public final class Parameters implements Cloneable, Serializable {
 
     public <S> Object[] getKeyValues(final Traverser.Admin<S> traverser, final
Object... exceptKeys) {
         if (this.parameters.size() == 0) return EMPTY_ARRAY;
-        final List<Object> exceptions = Arrays.asList(exceptKeys);
         final List<Object> keyValues = new ArrayList<>();
         for (final Map.Entry<Object, List<Object>> entry : this.parameters.entrySet())
{
-            if (!exceptions.contains(entry.getKey())) {
+            if (!ArrayUtils.contains(exceptKeys, entry.getKey())) {
                 for (final Object value : entry.getValue()) {
                     keyValues.add(entry.getKey() instanceof Traversal.Admin ? TraversalUtil.apply(traverser,
(Traversal.Admin<S, ?>) entry.getKey()) : entry.getKey());
                     keyValues.add(value instanceof Traversal.Admin ? TraversalUtil.apply(traverser,
(Traversal.Admin<S, ?>) value) : value);
@@ -159,7 +158,15 @@ public final class Parameters implements Cloneable, Serializable {
     }
 
     public <S, E> List<Traversal.Admin<S, E>> getTraversals() {
-        return (List) this.parameters.values().stream().flatMap(List::stream).filter(t ->
t instanceof Traversal.Admin).collect(Collectors.toList());
+        List<Traversal.Admin<S, E>> result = new ArrayList<>();
+        for (final List<Object> list : this.parameters.values()) {
+            for (final Object object : list) {
+                if (object instanceof Traversal.Admin) {
+                    result.add((Traversal.Admin) object);
+                }
+            }
+        }
+        return result;
     }
 
     public Parameters clone() {

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/42e771d7/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/finalization/EngineDependentStrategy.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/finalization/EngineDependentStrategy.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/finalization/EngineDependentStrategy.java
index 27b9ce0..3da8566 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/finalization/EngineDependentStrategy.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/finalization/EngineDependentStrategy.java
@@ -44,9 +44,11 @@ public final class EngineDependentStrategy extends AbstractTraversalStrategy<Tra
 
     @Override
     public void apply(final Traversal.Admin<?, ?> traversal) {
-        traversal.getSteps().stream()
-                .filter(step -> step instanceof EngineDependent)
-                .forEach(step -> ((EngineDependent) step).onEngine(traversal.getEngine()));
+        for (Step step : traversal.getSteps()) {
+            if (step instanceof EngineDependent) {
+                ((EngineDependent) step).onEngine(traversal.getEngine());
+            }
+        }
     }
 
     public static EngineDependentStrategy instance() {

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/42e771d7/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/DefaultTraversal.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/DefaultTraversal.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/DefaultTraversal.java
index 603ad10..bcc7aeb 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/DefaultTraversal.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/DefaultTraversal.java
@@ -52,6 +52,8 @@ public class DefaultTraversal<S, E> implements Traversal.Admin<S,
E> {
     private final StepPosition stepPosition = new StepPosition();
     protected transient Graph graph;
     protected List<Step> steps = new ArrayList<>();
+    // steps will be repeatedly retrieved from this traversal so wrap them once in an immutable
list that can be reused
+    protected List<Step> unmodifiableSteps = Collections.unmodifiableList(steps);
     protected TraversalParent traversalParent = (TraversalParent) EmptyStep.instance();
     protected TraversalSideEffects sideEffects = new DefaultTraversalSideEffects();
     protected TraversalStrategies strategies;
@@ -113,9 +115,11 @@ public class DefaultTraversal<S, E> implements Traversal.Admin<S,
E> {
 
     @Override
     public Set<TraverserRequirement> getTraverserRequirements() {
-        final Set<TraverserRequirement> requirements = this.getSteps().stream()
-                .flatMap(step -> ((Step<?, ?>) step).getRequirements().stream())
-                .collect(Collectors.toSet());
+        Set<TraverserRequirement> requirements = new HashSet<>();
+        for (Step step : this.getSteps()) {
+            requirements.addAll(step.getRequirements());
+        }
+
         requirements.addAll(this.traverserRequirements);
         if (this.getSideEffects().keys().size() > 0)
             requirements.add(TraverserRequirement.SIDE_EFFECTS);
@@ -135,7 +139,7 @@ public class DefaultTraversal<S, E> implements Traversal.Admin<S,
E> {
 
     @Override
     public List<Step> getSteps() {
-        return Collections.unmodifiableList(this.steps);
+        return unmodifiableSteps;
     }
 
     @Override
@@ -201,6 +205,7 @@ public class DefaultTraversal<S, E> implements Traversal.Admin<S,
E> {
         try {
             final DefaultTraversal<S, E> clone = (DefaultTraversal<S, E>) super.clone();
             clone.steps = new ArrayList<>();
+            clone.unmodifiableSteps = Collections.unmodifiableList(clone.steps);
             clone.sideEffects = this.sideEffects.clone();
             clone.strategies = this.strategies.clone();
             clone.lastEnd = null;

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/42e771d7/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/DefaultTraversalStrategies.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/DefaultTraversalStrategies.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/DefaultTraversalStrategies.java
index eb5a9c7..7eae1ea 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/DefaultTraversalStrategies.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/DefaultTraversalStrategies.java
@@ -92,7 +92,7 @@ public class DefaultTraversalStrategies implements TraversalStrategies {
     public DefaultTraversalStrategies clone() {
         try {
             final DefaultTraversalStrategies clone = (DefaultTraversalStrategies) super.clone();
-            clone.traversalStrategies = new ArrayList<>();
+            clone.traversalStrategies = new ArrayList<>(this.traversalStrategies.size());
             clone.traversalStrategies.addAll(this.traversalStrategies);
             return clone;
         } catch (final CloneNotSupportedException e) {

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/42e771d7/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/TraversalHelper.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/TraversalHelper.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/TraversalHelper.java
index a3a2dd6..b5c9fbc 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/TraversalHelper.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/TraversalHelper.java
@@ -183,7 +183,13 @@ public final class TraversalHelper {
     }
 
     public static <S> List<S> getStepsOfClass(final Class<S> stepClass,
final Traversal.Admin<?, ?> traversal) {
-        return (List) traversal.getSteps().stream().filter(step -> step.getClass().equals(stepClass)).collect(Collectors.toList());
+        List<S> steps = new ArrayList<>();
+        for (Step step : traversal.getSteps()) {
+            if (step.getClass().equals(stepClass)) {
+                steps.add((S) step);
+            }
+        }
+        return steps;
     }
 
     public static <S> List<S> getStepsOfAssignableClass(final Class<S>
stepClass, final Traversal.Admin<?, ?> traversal) {


Mime
View raw message