Skip to content

ANTLR tool takes 6s to process 1772 line parser grammar #3711

Open
@parrt

Description

@parrt

issue was identified in plugin by @KitsuneAlex

This FerrousParser.g4 takes 6s to process with antlr tool. It seems to be stuck in SLL(1) static analysis. Could be murmur hash or more likely LL1Analyzer.

Screen Shot 2022-05-15 at 11 56 22 AM

@sharwell This likely affects your optimized fork as well.

Simple test rig:

import org.antlr.runtime.ANTLRFileStream;
import org.antlr.runtime.ANTLRStringStream;
import org.antlr.v4.Tool;
import org.antlr.v4.tool.Grammar;
import org.antlr.v4.tool.ast.GrammarRootAST;

import java.io.IOException;

public class TestANTLRParse {
    public static void main(String[] args) throws IOException {
        long start = System.nanoTime();

        runANTLR(args[0]);

        long time_ns = System.nanoTime() - start;
        double parseTimeMS = time_ns/(1000.0*1000.0);
        System.err.println("Exec time to process "+args[0]+": "+parseTimeMS+"ms");
    }

    private static void runANTLR(String grammarFileName) throws IOException {
        Tool antlr = new Tool();

        ANTLRStringStream in = new ANTLRFileStream(grammarFileName);
        GrammarRootAST grammarRootAST = antlr.parse(grammarFileName, in);

        // Create a grammar from the AST so we can figure out what type it is
        Grammar g = antlr.createGrammar(grammarRootAST);
        antlr.process(g, false);
    }
}

I see this on M1 mac mini:

Exec time to process /Users/parrt/tmp/FerrousParser.g4: 5984.826209ms

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions