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

ASF GitHub Bot commented on TINKERPOP-1682:
-------------------------------------------

Github user dkuppitz commented on a diff in the pull request:

    https://github.com/apache/tinkerpop/pull/621#discussion_r176238971
  
    --- Diff: 
gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/ByModulatorOptimizationStrategy.java
 ---
    @@ -0,0 +1,110 @@
    +/*
    + * 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.traversal.strategy.optimization;
    +
    +import org.apache.tinkerpop.gremlin.process.traversal.Step;
    +import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
    +import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategy;
    +import 
org.apache.tinkerpop.gremlin.process.traversal.lambda.ElementValueTraversal;
    +import 
org.apache.tinkerpop.gremlin.process.traversal.lambda.IdentityTraversal;
    +import 
org.apache.tinkerpop.gremlin.process.traversal.lambda.TokenTraversal;
    +import org.apache.tinkerpop.gremlin.process.traversal.step.ByModulating;
    +import org.apache.tinkerpop.gremlin.process.traversal.step.TraversalParent;
    +import org.apache.tinkerpop.gremlin.process.traversal.step.map.IdStep;
    +import org.apache.tinkerpop.gremlin.process.traversal.step.map.LabelStep;
    +import 
org.apache.tinkerpop.gremlin.process.traversal.step.map.PropertiesStep;
    +import 
org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.IdentityStep;
    +import 
org.apache.tinkerpop.gremlin.process.traversal.strategy.AbstractTraversalStrategy;
    +import org.apache.tinkerpop.gremlin.structure.PropertyType;
    +import org.apache.tinkerpop.gremlin.structure.T;
    +
    +import java.util.Collections;
    +import java.util.HashSet;
    +import java.util.List;
    +import java.util.Set;
    +
    +/**
    + * This strategy looks for standard traversals in by-modulators and 
replaces them with more optimized traversals
    + * (e.g. {@code TokenTraversal}) if possible.
    + * <p/>
    + *
    + * @author Daniel Kuppitz (http://gremlin.guru)
    + * @example <pre>
    + * __.path().by(id())            // is replaced by __.path().by(id)
    + * __.dedup().by(label())        // is replaced by __.dedup().by(label)
    + * __.group().by(key())          // is replaced by __.group().by(key)
    + * __.group().by(value())        // is replaced by __.group().by(value)
    --- End diff --
    
    Oh right, I will remove them from the examples or add a note. key and value 
actually depend on  TINKERPOP-1689, which is still an open issue.


> by-modulator optimization strategy
> ----------------------------------
>
>                 Key: TINKERPOP-1682
>                 URL: https://issues.apache.org/jira/browse/TINKERPOP-1682
>             Project: TinkerPop
>          Issue Type: Improvement
>          Components: process
>    Affects Versions: 3.2.4
>            Reporter: Daniel Kuppitz
>            Assignee: Daniel Kuppitz
>            Priority: Major
>
> The can be a significant difference in performance depending on whether you 
> use {{by(id)}} or {{by(id())}}:
> {noformat}
> gremlin> g.V().out().in().path().by(id()).profile()
> ==>Traversal Metrics
> Step                                                               Count  
> Traversers       Time (ms)    % Dur
> =============================================================================================================
> TinkerGraphStep(vertex,[])                                             6      
>      6          12.137    58.03
> VertexStep(OUT,vertex)                                                 6      
>      6           1.345     6.43
> VertexStep(IN,vertex)                                                 12      
>     12           0.861     4.12
> PathStep([[IdStep, ProfileStep]])                                     12      
>     12           6.570    31.42
>   IdStep                                                              36      
>     36           0.452
>                                             >TOTAL                     -      
>      -          20.916        -
> gremlin> g.V().out().in().path().by(id).profile()
> ==>Traversal Metrics
> Step                                                               Count  
> Traversers       Time (ms)    % Dur
> =============================================================================================================
> TinkerGraphStep(vertex,[])                                             6      
>      6           0.876    11.54
> VertexStep(OUT,vertex)                                                 6      
>      6           0.714     9.40
> VertexStep(IN,vertex)                                                 12      
>     12           3.299    43.43
> PathStep([id])                                                        12      
>     12           2.706    35.63
>                                             >TOTAL                     -      
>      -           7.596        -
> {noformat}
> We should have a strategy that rewrites these simple patterns. This affects 
> {{id()}}, {{label()}}, {{key()}}, {{value()}}, but also 
> {{by(values("name"))}}, which can be rewritten as {{by("name")}}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to