tinkerpop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pie...@apache.org
Subject [50/50] [abbrv] tinkerpop git commit: Removed adding labels to the traverser in AbstractStep. Steps that call traverser.split(r, step) have already added the labels to the traverser. Steps that do not call traverser.split(r, step) add the labels manually
Date Mon, 19 Sep 2016 17:33:38 GMT
Removed adding labels to the traverser in AbstractStep.
Steps that call traverser.split(r, step) have already added the labels to the traverser.
Steps that do not call traverser.split(r, step) add the labels manually by overriding AbstractStep.prepareTraversalForNextStep().
ImmutablePath hold a direct reference to the labels. It no longer makes a copy.


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

Branch: refs/heads/TINKERPOP-1404
Commit: c1556fe82c58527dc4425d23d1d69ce324e62cfa
Parents: 54ed33d
Author: pieter <pieter.martin@gmail.com>
Authored: Wed Aug 24 12:47:35 2016 +0200
Committer: pieter <pieter@apache.org>
Committed: Mon Sep 19 19:30:31 2016 +0200

----------------------------------------------------------------------
 .../gremlin/process/GremlinPathBenchmark.java   | 70 ++++++++++++++++++++
 .../traversal/step/filter/FilterStep.java       |  9 +++
 .../traversal/step/map/NoOpBarrierStep.java     |  9 +++
 .../step/sideEffect/AggregateStep.java          |  9 +++
 .../step/sideEffect/SideEffectStep.java         |  9 +++
 .../traversal/step/sideEffect/StartStep.java    |  9 +++
 .../traversal/step/util/AbstractStep.java       |  4 +-
 .../step/util/CollectingBarrierStep.java        |  9 +++
 .../traversal/step/util/ImmutablePath.java      |  5 +-
 .../structure/util/detached/DetachedPath.java   | 11 +--
 10 files changed, 135 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/c1556fe8/gremlin-benchmark/src/main/java/org/apache/tinkerpop/gremlin/process/GremlinPathBenchmark.java
----------------------------------------------------------------------
diff --git a/gremlin-benchmark/src/main/java/org/apache/tinkerpop/gremlin/process/GremlinPathBenchmark.java
b/gremlin-benchmark/src/main/java/org/apache/tinkerpop/gremlin/process/GremlinPathBenchmark.java
new file mode 100644
index 0000000..5b60f5b
--- /dev/null
+++ b/gremlin-benchmark/src/main/java/org/apache/tinkerpop/gremlin/process/GremlinPathBenchmark.java
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tinkerpop.gremlin.process;
+
+import org.apache.tinkerpop.benchmark.util.AbstractGraphBenchmark;
+import org.apache.tinkerpop.gremlin.process.traversal.Path;
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
+import org.apache.tinkerpop.gremlin.structure.T;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.openjdk.jmh.annotations.Benchmark;
+import org.openjdk.jmh.annotations.BenchmarkMode;
+import org.openjdk.jmh.annotations.Mode;
+import org.openjdk.jmh.annotations.Setup;
+
+import java.io.IOException;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Date: 2016/07/22
+ * Time: 7:26 AM
+ */
+public class GremlinPathBenchmark extends AbstractGraphBenchmark {
+
+    private Vertex a;
+    private final static int COUNT = 1_000_000;
+
+    @Setup
+    public void prepare() throws IOException {
+        super.prepare();
+        a = graph.addVertex(T.label, "A", "name", "a1");
+        for (int i = 1; i < COUNT; i++) {
+            Vertex b = graph.addVertex(T.label, "B", "name", "name_" + i);
+            a.addEdge("outB", b);
+            for (int j = 0; j < 1; j++) {
+                Vertex c = graph.addVertex(T.label, "C", "name", "name_" + i + " " + j);
+                b.addEdge("outC", c);
+            }
+        }
+    }
+
+    @Benchmark
+    @BenchmarkMode(Mode.AverageTime)
+    public void g_path() throws Exception {
+        GraphTraversal<Vertex, Path> traversal = g.V(a).as("a").out().as("b").out().as("c").path();
+        int count = 1;
+        while (traversal.hasNext()) {
+            Path path = traversal.next();
+            count++;
+        }
+        assertEquals(COUNT, count);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/c1556fe8/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/FilterStep.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/FilterStep.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/FilterStep.java
index e07d951..ae8f5ee 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/FilterStep.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/FilterStep.java
@@ -40,5 +40,14 @@ public abstract class FilterStep<S> extends AbstractStep<S, S>
{
         }
     }
 
+    @Override
+    protected Traverser.Admin<S> prepareTraversalForNextStep(final Traverser.Admin<S>
traverser) {
+        super.prepareTraversalForNextStep(traverser);
+        if (!this.traverserStepIdAndLabelsSetByChild) {
+            traverser.addLabels(this.labels);
+        }
+        return traverser;
+    }
+
     protected abstract boolean filter(final Traverser.Admin<S> traverser);
 }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/c1556fe8/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/NoOpBarrierStep.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/NoOpBarrierStep.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/NoOpBarrierStep.java
index bedf078..32ac5be 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/NoOpBarrierStep.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/NoOpBarrierStep.java
@@ -57,6 +57,15 @@ public final class NoOpBarrierStep<S> extends AbstractStep<S,
S> implements Loca
     }
 
     @Override
+    protected Traverser.Admin<S> prepareTraversalForNextStep(final Traverser.Admin<S>
traverser) {
+        super.prepareTraversalForNextStep(traverser);
+        if (!this.traverserStepIdAndLabelsSetByChild) {
+            traverser.addLabels(this.labels);
+        }
+        return traverser;
+    }
+
+    @Override
     public Set<TraverserRequirement> getRequirements() {
         return Collections.singleton(TraverserRequirement.BULK);
     }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/c1556fe8/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/AggregateStep.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/AggregateStep.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/AggregateStep.java
index 7f4c993..b088bc5 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/AggregateStep.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/AggregateStep.java
@@ -111,6 +111,15 @@ public final class AggregateStep<S> extends AbstractStep<S,
S> implements SideEf
     }
 
     @Override
+    protected Traverser.Admin<S> prepareTraversalForNextStep(final Traverser.Admin<S>
traverser) {
+        super.prepareTraversalForNextStep(traverser);
+        if (!this.traverserStepIdAndLabelsSetByChild && !getLabels().isEmpty()) {
+            traverser.addLabels(getLabels());
+        }
+        return traverser;
+    }
+
+    @Override
     public void processAllStarts() {
         if (this.starts.hasNext()) {
             final BulkSet<Object> bulkSet = new BulkSet<>();

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/c1556fe8/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/SideEffectStep.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/SideEffectStep.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/SideEffectStep.java
index 46708d4..207cd0f 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/SideEffectStep.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/SideEffectStep.java
@@ -39,4 +39,13 @@ public abstract class SideEffectStep<S> extends AbstractStep<S,
S> {
         this.sideEffect(traverser);
         return traverser;
     }
+
+    @Override
+    protected Traverser.Admin<S> prepareTraversalForNextStep(final Traverser.Admin<S>
traverser) {
+        super.prepareTraversalForNextStep(traverser);
+        if (!this.traverserStepIdAndLabelsSetByChild) {
+            traverser.addLabels(this.labels);
+        }
+        return traverser;
+    }
 }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/c1556fe8/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/StartStep.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/StartStep.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/StartStep.java
index cfb7323..361228c 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/StartStep.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/StartStep.java
@@ -69,6 +69,15 @@ public class StartStep<S> extends AbstractStep<S, S> {
     }
 
     @Override
+    protected Traverser.Admin<S> prepareTraversalForNextStep(final Traverser.Admin<S>
traverser) {
+        super.prepareTraversalForNextStep(traverser);
+        if (!this.traverserStepIdAndLabelsSetByChild) {
+            traverser.addLabels(this.labels);
+        }
+        return traverser;
+    }
+
+    @Override
     public StartStep<S> clone() {
         final StartStep<S> clone = (StartStep<S>) super.clone();
         clone.first = true;

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/c1556fe8/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/AbstractStep.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/AbstractStep.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/AbstractStep.java
index 9eb1b3c..5e8d8e2 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/AbstractStep.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/AbstractStep.java
@@ -201,10 +201,10 @@ public abstract class AbstractStep<S, E> implements Step<S,
E> {
         return result;
     }
 
-    private final Traverser.Admin<E> prepareTraversalForNextStep(final Traverser.Admin<E>
traverser) {
+    protected Traverser.Admin<E> prepareTraversalForNextStep(final Traverser.Admin<E>
traverser) {
         if (!this.traverserStepIdAndLabelsSetByChild) {
             traverser.setStepId(this.nextStep.getId());
-            traverser.addLabels(this.labels);
+//            traverser.addLabels(this.labels);
         }
         return traverser;
     }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/c1556fe8/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/CollectingBarrierStep.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/CollectingBarrierStep.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/CollectingBarrierStep.java
index f9c85a2..057e1fa 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/CollectingBarrierStep.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/CollectingBarrierStep.java
@@ -112,6 +112,15 @@ public abstract class CollectingBarrierStep<S> extends AbstractStep<S,
S> implem
     }
 
     @Override
+    protected Traverser.Admin<S> prepareTraversalForNextStep(final Traverser.Admin<S>
traverser) {
+        super.prepareTraversalForNextStep(traverser);
+        if (!this.traverserStepIdAndLabelsSetByChild) {
+            traverser.addLabels(this.labels);
+        }
+        return traverser;
+    }
+
+    @Override
     public CollectingBarrierStep<S> clone() {
         final CollectingBarrierStep<S> clone = (CollectingBarrierStep<S>) super.clone();
         clone.traverserSet = new TraverserSet<>();

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/c1556fe8/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/ImmutablePath.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/ImmutablePath.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/ImmutablePath.java
index 729b4f3..03dc1e9 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/ImmutablePath.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/ImmutablePath.java
@@ -35,7 +35,7 @@ public class ImmutablePath implements Path, ImmutablePathImpl, Serializable,
Clo
 
     private ImmutablePathImpl previousPath = TailPath.instance();
     private Object currentObject;
-    private Set<String> currentLabels = new LinkedHashSet<>();
+    private Set<String> currentLabels;
 
     protected ImmutablePath() {
 
@@ -54,7 +54,7 @@ public class ImmutablePath implements Path, ImmutablePathImpl, Serializable,
Clo
     private ImmutablePath(final ImmutablePathImpl previousPath, final Object currentObject,
final Set<String> currentLabels) {
         this.previousPath = previousPath;
         this.currentObject = currentObject;
-        this.currentLabels.addAll(currentLabels);
+        this.currentLabels = currentLabels;
     }
 
     @Override
@@ -334,4 +334,5 @@ public class ImmutablePath implements Path, ImmutablePathImpl, Serializable,
Clo
             return other instanceof Path && ((Path) other).size() == 0;
         }
     }
+
 }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/c1556fe8/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedPath.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedPath.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedPath.java
index 10f9dfb..1158b02 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedPath.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedPath.java
@@ -24,6 +24,8 @@ import org.apache.tinkerpop.gremlin.structure.Element;
 import org.apache.tinkerpop.gremlin.structure.Property;
 import org.apache.tinkerpop.gremlin.structure.util.Attachable;
 
+import java.util.HashSet;
+import java.util.Set;
 import java.util.function.Function;
 
 /**
@@ -43,20 +45,19 @@ public class DetachedPath extends MutablePath implements Attachable<Path>
{
         path.forEach((object, labels) -> {
             if (object instanceof DetachedElement || object instanceof DetachedProperty ||
object instanceof DetachedPath) {
                 this.objects.add(object);
-                this.labels.add(labels);
             } else if (object instanceof Element) {
                 this.objects.add(DetachedFactory.detach((Element) object, withProperties));
-                this.labels.add(labels);
             } else if (object instanceof Property) {
                 this.objects.add(DetachedFactory.detach((Property) object));
-                this.labels.add(labels);
             } else if (object instanceof Path) {
                 this.objects.add(DetachedFactory.detach((Path) object, withProperties));
-                this.labels.add(labels);
             } else {
                 this.objects.add(object);
-                this.labels.add(labels);
             }
+            //Make a copy of the labels as its an UnmodifiableSet which can not be serialized.
+            Set<String> detachedLabels = new HashSet<>();
+            detachedLabels.addAll(labels);
+            this.labels.add(detachedLabels);
         });
     }
 


Mime
View raw message