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?
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);