antlr / antlr/antlr4

Antlr performance issue on unicode characters

Open
#2,467 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
19k
Forks
3.5k
PR merge metrics
No merged PRs in 30d

Description

Hi, I have developed a grammar using antlr4 with javascript as target language. The grammar works pretty well and is really fast. But on some inputs that have a mix of unicode and ASCII chars the performance is dropped.

For example:

An expression with 500 different terms with only ascii chars takes 100ms to be parsed.

An expression with 63 different terms in an arabic language takes 4 seconds.

On both expressions a few tokens are used, one to match the OR string and the other one to match a quotedString, the lexer rules are as follows

QUOTED_STRING: '"' (ESC | ~["\\])+ '"';
fragment ESC : '\\' (["\\/bfnrt] | UNICODE) ;
fragment UNICODE : 'u' HEX HEX HEX HEX ;
fragment HEX : [0-9a-fA-F] ;

OR: 'OR';

QUOTED_STRING was defined as '"' .+ '"'; before but getting advice from the Definitive Antlr Reference lead me to change it to the actual version. With this definition the performance was still an issue.

Contributor guide

Open the contributing guide

Research direction

No repository files or tests are named. Start by reproducing the reported JavaScript-target parsing benchmarks with the quoted-string lexer rules and mixed Unicode/ASCII inputs; done means identifying the cause of the slowdown and providing a verified performance fix or a clearly documented limitation.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
compilers, performance
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.