analyze-bottlenecks
Analyze ANTLR4 grammars to identify performance bottlenecks and receive prioritized optimization suggestions, including severity ratings and estimated improvement potential.
Instructions
Analyze grammar for performance bottlenecks and optimization opportunities.
When to use: Performance optimization, grammar refactoring, large grammar analysis.
Detects:
High-branching rules: Rules with many alternatives (10+, 20+, 50+)
Tilde negation patterns: ~NEWLINE, ~[ ] that could use lexer modes
Missing lexer mode opportunities: String handling, line-based content, multi-line blocks
Greedy loop issues: Nested quantifiers, reluctant patterns
Deep recursion: Rules with potential stack overflow risk
Token prefix collisions: Keywords that are prefixes of other keywords
Returns:
Bottlenecks with severity (high/medium/low)
Specific suggestions for each issue
Estimated performance improvement potential
Prioritized recommendations
Example: from_file: "MyGrammar.g4"
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| from_file | No | Optional: path to a grammar file to read | |
| grammar_content | No | The ANTLR4 grammar file content |