[ 
https://issues.apache.org/jira/browse/TINKERPOP-3313?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18146178#comment-18146178
 ] 

Stephen Mallette commented on TINKERPOP-3313:
---------------------------------------------

Thanks for offering this issue, but we likely won't make any changes to 
{{match()}} at this point. It is being completely reworked to support GQL in 
TinkerPop 4.0 and the form you're referring to is essentially deprecated: 
https://tinkerpop.apache.org/docs/4.0.0-beta.3/upgrade/#_declarative_pattern_matching

> match() re-runs an independent pattern for every traverser of the other 
> pattern
> -------------------------------------------------------------------------------
>
>                 Key: TINKERPOP-3313
>                 URL: https://issues.apache.org/jira/browse/TINKERPOP-3313
>             Project: TinkerPop
>          Issue Type: Bug
>          Components: process
>    Affects Versions: 3.5.1, 3.8.2
>            Reporter: Yuxuan Qing
>            Priority: Major
>              Labels: performance
>
> h1. match() re-runs an independent pattern for every traverser of the other 
> pattern
> h2. Describe the situation
> Hi, Apache TinkerPop developers,
> Please consider these two queries:
> {code:java}
> // q1
> g.V(root.id()).match(
> __.as('r').out('HIGH').as('m'),
> __.as('r').out('LOW').has('mark', false).as('f')
> ).select('r').constant(1){code}
> {code:java}
> // q2
> g.V(root.id()).match(
> __.as('r').out('LOW').has('mark', false).as('f'),
> __.as('r').out('HIGH').as('m')
> ).select('r').constant(1)
> {code}
> Neither pattern reads the other pattern's output label. The `Few` pattern has 
> no matches, so both queries return no rows. In q1, the same lookup for `Few` 
> is reached once per result of the `Many` pattern.
> 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 at the shared root 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 *920.335 ms / 0.478 ms* on JanusGraph and *1,419.501 ms / 
> 0.336 ms* on HugeGraph. The narrow pattern received 300,000 traversers in q1 
> and one in q2. Both queries returned no rows.
> 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').next()
> int n = 300000
> n.times
> { root.addEdge('HIGH', g.addV('Many').next()) }
> root.addEdge('LOW', g.addV('Few').property('mark', true).next())
> {code}
> The root has 300,000 `HIGH` edges and one `LOW` edge. The `LOW` neighbor has 
> `mark=true`, so the `mark=false` filter finds nothing.
> For q1, I get no rows. Median runtime on 3.8.2 is {*}276.842 ms{*}.
> For q2, I get no rows. Median runtime on 3.8.2 is {*}0.128 ms{*}.
> On 3.5.1 the full 300,000-edge measurement request exceeded Gremlin Server's 
> 120 s limit. With `n=1000`, both queries returned no rows and the medians 
> were *2.407 ms* for q1 and *0.084 ms* for q2.
>  
> TinkerGraph 3.8.2 `PROFILE` excerpt. Rows with blank counts are shown as 
> recorded.
> {code:java}
> Step Count Traversers Time (ms) % Dur
> q1
> MatchStartStep(r) 1 1 0.008
> VertexStep(OUT,[HIGH],vertex) 300000 300000 48.792
> MatchStartStep(r) 300000 300000 84.209
> VertexStep(OUT,[LOW],vertex) 300000 300000 73.478
> HasStep([mark.eq(false)]) 20.312
> q2
> MatchStartStep(r) 1 1 0.002
> VertexStep(OUT,[LOW],vertex) 1 1 0.002
> HasStep([mark.eq(false)]) 0.002
> MatchStartStep(r) 0.000
> VertexStep(OUT,[HIGH],vertex) 0.000
> {code}
> q1 passes 300,000 traversers with the same `r` binding into the `Few` 
> pattern. In q2, that pattern receives one traverser and returns nothing, so 
> the `Many` pattern is never reached.
> For a nonempty control, I removed the `mark=false` filter from the `LOW` 
> pattern in both queries. Both result lists contained 300,000 copies of `1`. 
> On 3.8.2, the `LOW` step produced 300,000 traversers when placed second and 
> one when placed first. The corresponding medians were *495.074 ms* and 
> {*}277.114 ms{*}.
> h2. Expected performance
> Please consider avoiding repeated evaluation of a read-only `match()` pattern 
> when all its input bindings are identical, including when the pattern returns 
> no matches.



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to