简体   繁体   中英

How to speed up JavaParser

I'm using JavaParser v3.13.5 to build AST from an expressions. I have spotted that parsing expression even simple like Objects.equals(a, b) takes up too much time (~0.15 s). Are there any options, besides ParserConfiguration , to speed up parsing?

EDIT

Code to reproduce results:

JavaParser javaParser = new JavaParser(
        new ParserConfiguration()
                .setStoreTokens(false)
                .setAttributeComments(false)
                .setDoNotAssignCommentsPrecedingEmptyLines(true)
                .setIgnoreAnnotationsWhenAttributingComments(true)
                .setLexicalPreservationEnabled(true)
                .setPreprocessUnicodeEscapes(false)
                .setLanguageLevel(LanguageLevel.RAW)
                .setCharacterEncoding(Providers.UTF8));

String strExpr = "Objects.equals(a, b)";

long start = System.currentTimeMillis();
//Expression expr = StaticJavaParser.parseExpression(strExpr); // even slower...
ParseResult<Expression> parseResult = javaParser.parseExpression(strExpr); // slow...
long end = System.currentTimeMillis();

System.out.println((double) (end-start)/1000);

Is there any method which can be overriden to suppress some unnecessary validations or something else?

也许您可以禁用示例中未使用的 LexicalPreservation。

Actually (JP version 3.16.3) takes 2983.4 nano seconds to parse this statement.

 String code = "Objects.equals(a, b);";
 long start = System.nanoTime();
 Statement stmt = StaticJavaParser.parseStatement(code);
 long end = System.nanoTime();
 System.out.println((double) (end-start)/1000);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM