You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2021/08/29 08:32:31 UTC

[groovy] branch master updated: Add the doco for tuning performance of parrot parser

This is an automated email from the ASF dual-hosted git repository.

sunlan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git


The following commit(s) were added to refs/heads/master by this push:
     new aeba9f8  Add the doco for tuning performance of parrot parser
aeba9f8 is described below

commit aeba9f8893042eaed3825876595f4c1fbd41c08f
Author: Daniel Sun <su...@apache.org>
AuthorDate: Sun Aug 29 16:32:15 2021 +0800

    Add the doco for tuning performance of parrot parser
---
 .../internal/atnmanager/LexerAtnManager.java       |  2 +-
 src/spec/doc/performance-guide.adoc                | 33 ++++++++++++++++++++++
 2 files changed, 34 insertions(+), 1 deletion(-)

diff --git a/src/main/java/org/apache/groovy/parser/antlr4/internal/atnmanager/LexerAtnManager.java b/src/main/java/org/apache/groovy/parser/antlr4/internal/atnmanager/LexerAtnManager.java
index f2a6f9c..2b7d560 100644
--- a/src/main/java/org/apache/groovy/parser/antlr4/internal/atnmanager/LexerAtnManager.java
+++ b/src/main/java/org/apache/groovy/parser/antlr4/internal/atnmanager/LexerAtnManager.java
@@ -26,7 +26,7 @@ import org.apache.groovy.util.SystemUtil;
  * Manage ATN for lexer to avoid memory leak
  */
 public class LexerAtnManager extends AtnManager {
-    private static final String GROOVY_CLEAR_LEXER_DFA_CACHE = "groovy.clear.lexer.dfa.cache";
+    private static final String GROOVY_CLEAR_LEXER_DFA_CACHE = "groovy.antlr4.clear.lexer.dfa.cache";
     private static final boolean TO_CLEAR_LEXER_DFA_CACHE;
     private final AtnWrapper lexerAtnWrapper = new AtnManager.AtnWrapper(GroovyLangLexer._ATN);
     public static final LexerAtnManager INSTANCE = new LexerAtnManager();
diff --git a/src/spec/doc/performance-guide.adoc b/src/spec/doc/performance-guide.adoc
new file mode 100644
index 0000000..e8e1e76
--- /dev/null
+++ b/src/spec/doc/performance-guide.adoc
@@ -0,0 +1,33 @@
+//////////////////////////////////////////
+
+  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.
+
+//////////////////////////////////////////
+
+= Tune parsing performance of Parrot parser
+
+The Parrot parser is based on antlr4 and introduced since Groovy 3.0.0. It provides the following options to tune parsing performance:
+
+[cols="<,<,<,<,<",options="header"]
+|=======================================================================
+| Option | Description | Default | Version | Example
+| groovy.parallel.parse | Parsing groovy source file in parallel. | `false` util Groovy 4.0.0 | 3.0.5+ | -Dgroovy.parallel.parse=true
+| groovy.antlr4.cache.threshold | antlr4 relies on DFA cache heavily for better performance, so antlr4 will not clear DFA cache, thus OutOfMemoryError will probably occur. Groovy trades off parsing performance and memory usage, when the count of Groovy source files parsed hits the cache threshold, the DFA cache will be cleared. *Note:* `0` means never clearing DFA cache, so requiring bigger JVM heap size. Or set a greater value, e.g. 200 to clear DFA cache if threshold hits. **Note: ** t [...]
+| groovy.antlr4.sll.threshold | Parrot parser will try SLL mode and then try LL mode if SLL failed. But the more tokens to parse, the more likely SLL will fail. If SLL threshold hits, SLL will be skipped. **Note: ** the threshold specified is the token count | -1 (disabled by default) | 3.0.9+ | -Dgroovy.antlr4.sll.threshold=1000
+| groovy.antlr4.clear.lexer.dfa.cache | Clear the DFA cache for lexer. The DFA cache for lexer is always small and important for parsing performance, so it's strongly recommended to leave it as it is util OutOfMemoryError will truely occur | `false`| 3.0.9+ | -Dgroovy.antlr4.clear.lexer.dfa.cache=true
+|=======================================================================