Skip to content

[Pratt parser] Add parser recursion depth benchmark test - #1440

Merged
dmitriplotnikov merged 1 commit into
pratt-parser-optionfrom
parser-recursion-depth-test
Aug 27, 2026
Merged

[Pratt parser] Add parser recursion depth benchmark test#1440
dmitriplotnikov merged 1 commit into
pratt-parser-optionfrom
parser-recursion-depth-test

Conversation

@dmitriplotnikov

@dmitriplotnikov dmitriplotnikov commented Aug 27, 2026

Copy link
Copy Markdown
Collaborator

Overview

Add TestParserRecursionDepth to measure stack memory consumption and crash boundaries when parsing deeply nested expressions in ANTLR vs Pratt parsers.

Recursion Depth Comparison (Stack: 64 KB)

Category ANTLR (Max Depth OK) Pratt (Max Depth OK) Pratt Advantage
Parens ((((...42...)))) 20 unlimited inf
Unary (! ! ! ... true) unlimited unlimited 1.0x
Binary (1 + (1 + (...42...))) 21 93 ~4.4x
List ([[[...42...]]]) 18 85 ~4.7x

Add TestParserRecursionDepth to measure stack memory consumption and crash boundaries when parsing deeply nested expressions in ANTLR vs Pratt parsers.

### Recursion Depth Comparison (Stack: 64 KB, Max Depth: 1000)

| Category | ANTLR (Max Depth OK) | Pratt (Max Depth OK) | Pratt Advantage |
| :--- | :--- | :--- | :--- |
| **Parens** (`(((...42...)))`) | 20 | unlimited | **unlimited** |
| **Unary** (`! ! ! ... true`) | unlimited | unlimited | **1.0x** |
| **Binary** (`1 + (1 + (...42...))`) | 21 | 93 | **~4.4x** |
| **List** (`[[[...42...]]]`) | 18 | 85 | **~4.7x** |
@dmitriplotnikov
dmitriplotnikov merged commit 9008587 into pratt-parser-option Aug 27, 2026
6 checks passed
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

Successfully merging this pull request may close these issues.

2 participants