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

Warn about semantics predicate at the beginning of lexer rule because of it degradates performance a lot #3633

Open
KvanTTT opened this issue Apr 8, 2022 · 4 comments

Comments

@KvanTTT
Copy link
Member

KvanTTT commented Apr 8, 2022

From the article: https://tomassetti.me/improving-the-performance-of-an-antlr-parser/ :

Mike Lischke, pointed out is that you should not put one at the beginning of a lexer rule. That is because rules with semantic predicates at the beginning are not cached. And in lexer rules the effect of no caching, is really heavy. All lexer rules are handled as if they were alternatives in a single big outer rule. So, even if only one lexer rule contains a predicate on the left hand side, no lexer rule is cached at all! When you consider that all your keywords also are lexer rules, you can easily imagine how thousands of lexer rules behave, performance-wise, if they are not cached.

I've also encountered the degradation several times.

TOKEN_1: {code}? 'TOKEN_1; // Warning
TOKEN_2: 'TOKEN_2' {code}?; // Ok

@mike-lischke what do you think about introducing of such warning?

@mike-lischke
Copy link
Member

You mean having the ANTLR4 tool spit out a warning like that?

@KvanTTT
Copy link
Member Author

KvanTTT commented Apr 8, 2022

Yes, something like Semantics predicate at the beginning of the lexer rule significantly degradates performance

@mike-lischke
Copy link
Member

Sounds good, sure!

@KvanTTT
Copy link
Member Author

KvanTTT commented Apr 8, 2022

Also, I suggest copying this info from the article to the ANTLR documentation.

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

No branches or pull requests

2 participants