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

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

spmallette opened a new pull request, #2094:
URL: https://github.com/apache/tinkerpop/pull/2094

   https://issues.apache.org/jira/browse/TINKERPOP-2959
   
   This adds functionality similar to `GremlinGroovyScriptEngine` where 
bindings can be applied to a script as in `g.V(x)` where `x` is a variable that 
can be bound to a value external to the script. This functionality doesn't 
offer any particular performance enhancement for the grammar the way that it 
does for groovy but it does better allow one engine to be swapped for the other 
which is crucial for a migration away from the groovy engine. This change also 
opens up better opportunities for translator and gherkin improvements as well.
   
   Purposefully did not add upgrade docs as I still don't think this 
functionality is completely ready for general usage.
   
   This is a fairly large diff because it essentially rewrites the core of the 
antlr grammar and that force a rewrite of much of the parser. It might be best 
to focus on what's being tested and to try to determine if anything further 
should be tested in relation to this functionality. 
   
   Performance testing showed that somehow, these changes actually made the 
parser a tiny bit faster. I basically ran all the Gremlin (minus a few 
troublemakers) in the documentation (about 600 queries) through the parser 
10000 times. My runs with these changes tended to finish in about 65~ seconds 
typically. Runs on `master` prior to these changes typically ran around 72~ 
seconds. Here's the script which I just pasted into Gremlin Console (if you 
want to run be sure to replace `TINKERPOP_HOME_PATH` with the path to your 
TinkerPop git repo home:
   
   ```groovy
   import org.apache.tinkerpop.gremlin.language.corpus.*
   g = TinkerGraph.open().traversal()
   b = new javax.script.SimpleBindings()
   b.put('g', g)
   lang = new GremlinLangScriptEngine()
   home = 'TINKERPOP_HOME_PATH'
   gremlins = DocumentationReader.parse(home + '/docs/src'); []
   gremlins = gremlins.findAll{ !it.contains("g.union") && 
!it.contains("coalesce(E") && !it.contains("eq(constant('josh'))") && 
!it.contains("xx") && !it.contains("branch") && !it.contains("program") && 
!it.contains("profile") && !it.contains("explain") && 
!it.contains("connectedComponent") && !it.contains("fill") && 
!it.contains("next") && !it.contains("toList") && !it.contains("iterate") && 
!it.contains("withComputer") && !it.contains("{") && 
!it.contains("withoutStrategies") };[]
   start = System.currentTimeMillis()
   gremlins.each { lang.eval(it, b);[] }
   (0..10000).each {
       if (it % 10 == 9) 
           println "."
       else 
           print "."
       gremlins.each { lang.eval(it, b);[] }
   }
   end = System.currentTimeMillis() - start
   ```
   
   VOTE +1




> Allow the grammar to support parameters
> ---------------------------------------
>
>                 Key: TINKERPOP-2959
>                 URL: https://issues.apache.org/jira/browse/TINKERPOP-2959
>             Project: TinkerPop
>          Issue Type: Improvement
>          Components: language
>    Affects Versions: 3.6.4
>            Reporter: Stephen Mallette
>            Priority: Major
>
> Allow the grammar to support parameters similar to how the groovy engine does 
> like, {{g.inject(x,y,z)}}. Doing this will make it easier for a transition 
> away from the groovy engine as a lot of Gremlin in the world today uses 
> parameters. The grammar may have to come with some limitations though as 
> groovy is wide open in terms of what can be treated as a variable. Probably 
> going to keep parameters tied to primitives, collections and tokens/enums 
> like {{Order}} and {{Scope}}. Collections themselves will not contain 
> parameters and things like a {{Traversal}} or {{P}} cannot be treated as one.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to