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/28 12:21:27 UTC

[groovy] branch danielsun/parrot-statistics updated (98274d1 -> d300ef8)

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

sunlan pushed a change to branch danielsun/parrot-statistics
in repository https://gitbox.apache.org/repos/asf/groovy.git.


 discard 98274d1  Statistics for ALL
     new d300ef8  Add option `groovy.antlr4.sll.threshold` for better parsing performance

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (98274d1)
            \
             N -- N -- N   refs/heads/danielsun/parrot-statistics (d300ef8)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../apache/groovy/parser/antlr4/AstBuilder.java    | 27 +++++++++++++++-------
 1 file changed, 19 insertions(+), 8 deletions(-)

[groovy] 01/01: Add option `groovy.antlr4.sll.threshold` for better parsing performance

Posted by su...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

sunlan pushed a commit to branch danielsun/parrot-statistics
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit d300ef8df14a151803807599b964834b8cca73cf
Author: Daniel Sun <su...@apache.org>
AuthorDate: Sat Aug 28 20:20:43 2021 +0800

    Add option `groovy.antlr4.sll.threshold` for better parsing performance
---
 .../apache/groovy/parser/antlr4/AstBuilder.java    | 26 ++++++++++++++++------
 1 file changed, 19 insertions(+), 7 deletions(-)

diff --git a/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java b/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java
index 14e2380..53adba7 100644
--- a/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java
+++ b/src/main/java/org/apache/groovy/parser/antlr4/AstBuilder.java
@@ -210,6 +210,7 @@ import org.apache.groovy.parser.antlr4.internal.DescriptiveErrorStrategy;
 import org.apache.groovy.parser.antlr4.internal.atnmanager.AtnManager;
 import org.apache.groovy.parser.antlr4.util.StringUtils;
 import org.apache.groovy.util.Maps;
+import org.apache.groovy.util.SystemUtil;
 import org.codehaus.groovy.GroovyBugError;
 import org.codehaus.groovy.antlr.EnumHelper;
 import org.codehaus.groovy.ast.ASTNode;
@@ -404,14 +405,23 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> {
             // parsing have to wait util clearing is complete.
             AtnManager.READ_LOCK.lock();
             try {
-                result = buildCST(PredictionMode.SLL);
-            } catch (Throwable t) {
-                // if some syntax error occurred in the lexer, no need to retry the powerful LL mode
-                if (t instanceof GroovySyntaxError && GroovySyntaxError.LEXER == ((GroovySyntaxError) t).getSource()) {
-                    throw t;
-                }
+                if (SLL_THRESHOLD > 0 && parser.getInputStream().size() > SLL_THRESHOLD) {
+                    // The more tokens to parse, the more possibility SLL will fail and waste lots of parsing time.
+                    // The option `groovy.antlr4.sll.threshold` could be tuned for better parsing performance, but it is disabled by default.
+                    // if the token count is greater than `SLL_THRESHOLD`, use ALL directly.
+                    result = buildCST(PredictionMode.LL);
+                } else {
+                    try {
+                        result = buildCST(PredictionMode.SLL);
+                    } catch (Throwable t) {
+                        // if some syntax error occurred in the lexer, no need to retry the powerful LL mode
+                        if (t instanceof GroovySyntaxError && GroovySyntaxError.LEXER == ((GroovySyntaxError) t).getSource()) {
+                            throw t;
+                        }
 
-                result = buildCST(PredictionMode.LL);
+                        result = buildCST(PredictionMode.LL);
+                    }
+                }
             } finally {
                 AtnManager.READ_LOCK.unlock();
             }
@@ -5031,6 +5041,8 @@ public class AstBuilder extends GroovyParserBaseVisitor<Object> {
     private int visitingAssertStatementCount;
     private int visitingArrayInitializerCount;
 
+    private static final int SLL_THRESHOLD = SystemUtil.getIntegerSafe("groovy.antlr4.sll.threshold", -1);
+
     private static final String QUESTION_STR = "?";
     private static final String DOT_STR = ".";
     private static final String SUB_STR = "-";