[
https://issues.apache.org/jira/browse/TINKERPOP-3311?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18146375#comment-18146375
]
Cole Greer commented on TINKERPOP-3311:
---------------------------------------
Hi, thanks for reporting this and several other opportunities for further
optimizations in gremlin.
I want to share my view on TInkerPop's role in optimizing gremlin, as I think
that informs how most of your recently reported issues should be handled.
TinkerPop does maintain a small handful of optimizing traversal strategies such
as CountStrategy and FilterRankingStrategy which aim make generalized
structural rewrites of sub-optimal gremlin traversals, however these are rather
limited as we cannot infer much about the users graph data or system. I mostly
view gremlin optimization as a provider responsibility, as they can go much
further in tuning a query based on their underlying storage model and engine,
or potentially based on schema information such as cardinality and degrees of
various labels.
I'm happy to pick up a few additional optimizing strategies in TinkerPop if
they are fully generalizable and would provide value to most providers, however
there are limits to how much we can reasonably do based on the data we have
available in TinkerPop.
Looking specifically at this case here, it would be reasonable to have a
strategy which identifies some common patterns of tautologies or contradictions
inside filters. In the case of a tautology, the filter could be removed
entirely, and in the case of a contradiction, it could be replaced with the
discard() step. It's certainly worth exploring what sort of
tautology/contradiction patterns we can reasonably detect without access to
specific graph stats or schema. I suspect there is very little we can do beyond
the constant()-based examples in this ticket, but it would be worth exploring.
My view on the constant() cases is that they are a bit artificial. I wouldn't
expect queries like that to be used in "real-world" production deployments,
which limits the overall upside in the optimization. Please let me know if
there are use cases for such query patterns which I'm overlooking.
> A constant-false child filter still expands every neighbor
> ----------------------------------------------------------
>
> Key: TINKERPOP-3311
> URL: https://issues.apache.org/jira/browse/TINKERPOP-3311
> Project: TinkerPop
> Issue Type: Bug
> Components: process, tinkergraph
> Affects Versions: 3.5.1, 3.8.2
> Reporter: Yuxuan Qing
> Priority: Major
> Labels: performance
>
> h1. A constant-false child filter still expands every neighbor
> h2. Describe the situation
> Hi, Apache TinkerPop developers,
> Please consider these two queries:
> {code:java}
> // q1
> g.V(root.id()).out('HIGH').filter(__.constant(2).is(P.lt(1))
> ).constant(1)
> {code}
> {code:java}
> // q2
> g.V(root.id()).out('LOW').filter(__.constant(2).is(P.lt(1))
> ).constant(1)
> {code}
> Each query expands one edge label and then applies the same constant
> comparison, `2 < 1`. That comparison always rejects the input. Both queries
> return no rows.
> h2. Which Apache TinkerPop versions are affected?
> I reproduced this with TinkerGraph 3.8.2 (OpenJDK 11.0.32.1) and TinkerGraph
> 3.5.1 (OpenJDK 11.0.30), using Gremlin-Groovy and the default traversal
> strategies. The TinkerGraph measurements below ran in a fresh in-memory graph
> in a Gremlin Server JVM in Docker on macOS ARM64.
> I also ran the same query pair with 300,000 HIGH neighbors and one LOW
> neighbor on JanusGraph 1.2.0 (TinkerPop 3.8.2, BerkeleyJE) and HugeGraph
> 1.7.0 (TinkerPop 3.5.1, RocksDB). The median JVM runtimes for q1 and q2 were
> *363.223 ms / 0.357 ms* on JanusGraph and *252.663 ms / 0.148 ms* on
> HugeGraph. Both providers emitted 300,000 and one neighbors into the
> constant-false filter in q1 and q2, respectively.
> h2. How to reproduce
> Run this setup, then run q1 and q2 with the same traversal source. Consume
> the results using `toList()`.
> {code:java}
> import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph
> def tg = TinkerGraph.open()
> def g = tg.traversal()
> def root = g.addV('Root').property('anchor', 1).next()
> 300000.times {
> root.addEdge('HIGH', g.addV('Leaf').property('mark', true).next())
> }
> root.addEdge('LOW', g.addV('Leaf').property('mark', true).next())
> {code}
> The root has 300,000 neighbors under `HIGH` and one neighbor under `LOW`.
> For q1, I get no rows. Median runtime on 3.8.2 is {*}125.833 ms{*}{*}.{*} On
> 3.5.1 it is {*}120.922 ms{*}.
> For q2, I get no rows. Median runtime on 3.8.2 is {*}0.094 ms{*}{*}.{*} On
> 3.5.1 it is {*}0.090 ms{*}.
>
> TinkerGraph 3.8.2 `PROFILE` excerpt. Rows with blank counts are shown as
> recorded.
> {code:java}
> Step Count Traversers Time (ms) % Dur
> q1
> VertexStep(OUT,[HIGH],vertex) 300000 300000 26.867 10.95
> TraversalFilterStep([ConstantStep(2), IsStep(lt... 218.394 89.02
> q2
> VertexStep(OUT,[LOW],vertex) 1 1 0.010 13.24
> TraversalFilterStep([ConstantStep(2), IsStep(lt... 0.013 16.76
> {code}
> The final plans retain the constant comparison after the vertex expansion.
> The expansion supplies 300,000 inputs to the filter in q1 and one in q2.
> h2. Expected performance
> Please fold a pure constant-false child filter so the traversal can skip the
> preceding read-only expansion.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)