I compared the time cost by antlr2 parser and Parrot parser via running the
following script "Parse.groovy", which is placed under directory
"nextflow-master\modules\nextflow\src\main\groovy\nextflow"[1]:
The heap size is set to 2G, i.e. "-Xms2g -Xmx2g"
1) run antlr2 parser
`groovy Parse.groovy 2`
cost 57.177s
2) run Parrot parser:
`groovy Parse.groovy 4`
As 364 groovy source files in all, we set threshold to 600 (> 364) to avoid
cache being cleared
with "-Dgroovy.antlr4.cache.threshold=600": cost 58.672s // almost same to
antlr2 parser
without "groovy.antlr4.cache.threshold" setting: cost 67.183s
(Parse.groovy)
```
import groovy.io.FileType
import org.apache.groovy.parser.*
def parserVer = args[0]
def result = []
def parser = '4' == parserVer ? new Antlr4Parser() : new Antlr2Parser()
println "${parser.class} enabled!"
new File('.').eachFileRecurse (FileType.FILES) { file ->
if (!file.name.endsWith('.groovy')) return
println "Parsing $file"
def b = System.currentTimeMillis()
parser.parse(file)
def e = System.currentTimeMillis()
result << Tuple.tuple((e - b), file)
}
println "------------ RESULT --------------"
result.sort { o1, o2 -> o2.v1 <=> o1.v1 }.each {
println "${it.v1 / 1000}s\t\t\t\t\t${it.v2}"
}
println "# ${result.sum { it.v1 } / 1000}s elapsed"
```
Cheers,
Daniel.Sun
[1] https://github.com/nextflow-io/nextflow/archive/master.zip
On 2020/01/17 18:08:22, "Daniel.Sun" <[email protected]> wrote:
> If you find the performance issue is gone when you disable the Parrot parser
> with `-Dgroovy.antlr4=false`, you can try to enable the Parrot parser again
> and apply `-Dgroovy.antlr4.cache.threshold=200` shown as follows.
>
> ```
> compileGroovy {
> groovyOptions.fork = true
> groovyOptions.forkOptions.jvmArgs +=
> ["-Dgroovy.antlr4.cache.threshold=200"] // you can try to increase the
> threshold if your project contains many Groovy source files.
> }
> ```
>
> The greater the value of threshold is, the longer the cache will be
> reused(i.e. not be cleared), but it will require bigger JVM heap.
>
> Note: antlr4 recommends never to clear the cache for better performance, but
> Parrot parser will clear the cache to avoid OOME when threshold reaches.
>
> Cheers,
> Daniel.Sun
>
>
>
> -----
> Apache Groovy committer & PMC member
> Blog: http://blog.sunlan.me
> Twitter: @daniel_sun
>
> --
> Sent from: http://groovy.329449.n5.nabble.com/Groovy-Dev-f372993.html
>