Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
parrt opened this issue May 15, 2022 · 1 comment
Open

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

parrt opened this issue May 15, 2022 · 1 comment

Comments

@parrt
Copy link
Member

parrt commented May 15, 2022

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
@KitsuneAlex
Copy link

I'll be touching up on this very soon, most likely on the weekend. I got some nice PRs ready and i'm excited to share them finally. Also, that test rig doesn't seem like a good idea, because you don't even warumup the VM/JIT, so the results will be all over the place. I suggest at least adding a loop before the actual test, calling the function to test a couple thousand times, so it get's JITed into the global code cache.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants