Repository navigation
Performance andtlr improvements #6
Unanswered
jagalindo
asked this question in
Enhancement Proposals
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Summary
Parsing UVL is several times slower than it needs to be because of a single semantic predicate in the NEWLINE lexer rule. This PR removes it from the Python, Java and JavaScript lexers without changing the token stream. Every model lexes to the same tokens, and indented first lines are still rejected.
Problem
All three target lexers define
antlr
NEWLINE: (
{atStartOfInput()}? SPACES
| ( '\r'? '\n' | '\r') SPACES?
) {handleNewline();};
The {atStartOfInput()}? predicate is reachable from the lexer's start state. In that case ANTLR's LexerATNSimulator.matchATN never stores the DFA start state (suppressEdge = s0_closure.hasSemanticContext), so every token recomputes the whole ATN closure instead of reusing the cached DFA.
Measured with the Python target (uvlparser 2.5.0) on a 1.5 MB UVLHub model (BerkeleyDB, 224,698 tokens):
Java and JavaScript use the same matchATN logic, so they have the same problem.
Change (implemented on a new branch)
Behaviour
Unchanged, including the rejection of an indented first line:
features
Root
still fails with Line 1:2 - no viable alternative at input ' ', as before.
Tests
Verification
All reactions