You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by va...@apache.org on 2023/10/20 22:55:38 UTC
[tinkerpop] branch master updated: [TINKERPOP-3004] improve GremlinValueComparator performance (#2282)
This is an automated email from the ASF dual-hosted git repository.
valentyn pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tinkerpop.git
The following commit(s) were added to refs/heads/master by this push:
new 732d1a2790 [TINKERPOP-3004] improve GremlinValueComparator performance (#2282)
732d1a2790 is described below
commit 732d1a2790824d3ba730aaca78c3d1d86d56b75a
Author: Valentyn Kahamlyk <vk...@users.noreply.github.com>
AuthorDate: Fri Oct 20 15:55:32 2023 -0700
[TINKERPOP-3004] improve GremlinValueComparator performance (#2282)
---
CHANGELOG.asciidoc | 1 +
.../gremlin/util/GremlinValueComparator.java | 13 ++++++---
.../tinkergraph/structure/TinkerGraphPlayTest.java | 33 ++++++++++++++++++++++
3 files changed, 43 insertions(+), 4 deletions(-)
diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index bd2ac43854..05f10ea3cc 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -38,6 +38,7 @@ This release also includes changes from <<release-3-6-5, 3.6.6>> and <<release-3
* Added getter for `isStart` on `UnionStep`.
* Added `agent` parameter to `DriverRemoteConnection` options to allow a user-provided `http.Agent` implementation.
* Fixed bug in `union()` as a start step where the `Path` was including the starting dummy traverser.
+* Improved performance for element comparison.
[[release-3-7.0]]
=== TinkerPop 3.7.0 (Release Date: July 31, 2023)
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/util/GremlinValueComparator.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/util/GremlinValueComparator.java
index ea2566feee..f99c191b30 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/util/GremlinValueComparator.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/util/GremlinValueComparator.java
@@ -125,6 +125,11 @@ public abstract class GremlinValueComparator implements Comparator<Object> {
*/
@Override
public boolean equals(final Object f, final Object s) {
+ // numbers and collections with different hashcode can be equal
+ if (f != null && s != null && f.hashCode() != s.hashCode()
+ && !(f instanceof Number) && !(f instanceof Collection) && !(f instanceof Map))
+ return false;
+
// shortcut a long, drawn out element by element comparison
if (containersOfDifferentSize(f, s))
return false;
@@ -138,9 +143,9 @@ public abstract class GremlinValueComparator implements Comparator<Object> {
return false;
try {
- // comparable(f, s) assures that type(f) == type(s)
- final Type type = Type.type(f);
- return comparator(type).compare(f, s) == 0;
+ // comparable(f, s) assures that type(f) == type(s)
+ final Type type = Type.type(f);
+ return comparator(type).compare(f, s) == 0;
} catch (GremlinTypeErrorException ex) {
/**
* By routing through the compare(f, s) path we expose ourselves to type errors, which should be
@@ -151,7 +156,7 @@ public abstract class GremlinValueComparator implements Comparator<Object> {
*
* Can also happen for elements nested inside of collections.
*/
- return false;
+ return false;
}
}
diff --git a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphPlayTest.java b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphPlayTest.java
index 3489fcf3cd..3560027d2f 100644
--- a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphPlayTest.java
+++ b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphPlayTest.java
@@ -19,6 +19,7 @@
package org.apache.tinkerpop.gremlin.tinkergraph.structure;
import org.apache.tinkerpop.gremlin.process.computer.Computer;
+import org.apache.tinkerpop.gremlin.process.traversal.P;
import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
@@ -45,6 +46,7 @@ import java.util.function.Supplier;
import static org.apache.tinkerpop.gremlin.process.traversal.Operator.sum;
import static org.apache.tinkerpop.gremlin.process.traversal.P.neq;
+import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal.Symbols.values;
import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.as;
import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.both;
import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.choose;
@@ -56,6 +58,7 @@ import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.sack;
import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.select;
import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.union;
import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.valueMap;
+import static org.apache.tinkerpop.gremlin.structure.Column.keys;
/**
* @author Stephen Mallette (http://stephen.genoprime.com)
@@ -282,4 +285,34 @@ public class TinkerGraphPlayTest {
union(__.repeat(out().simplePath()).times(2).count(),
__.repeat(in().simplePath()).times(2).count());
}
+
+ @Test
+ @Ignore
+ public void WithinTest() {
+ final int count = 500;
+
+ final Graph graph = TinkerGraph.open();
+ final GraphTraversalSource g = graph.traversal();
+ for (int i = 0; i < count; i++) {
+ graph.addVertex(T.label, "person", T.id, i);
+ }
+
+ graph.vertices().forEachRemaining(a -> {
+ graph.vertices().forEachRemaining(b -> {
+ if (a != b && ((int) a.id() < 2 || (int) b.id() < 2)) {
+ a.addEdge("knows", b);
+ }
+ });
+ });
+
+ final long start = System.currentTimeMillis();
+
+ final List result = g.
+ V().has(T.id,P.lt(count/2)).aggregate("v1").
+ V().where(P.without("v1")).
+ toList();
+
+ System.out.println(result.size());
+ System.out.printf("Done in %10d %n", System.currentTimeMillis() - start);
+ }
}