Commit 1b51f05
committed
perf: grammar tower + Pratt parser + LOOKAHEAD optimization (~15% speedup)
Replace exponential-backtracking grammar with targeted optimizations:
- Add prattArithRest() Java loop for arithmetic (eliminates AddChain/MulChain method calls)
- Add prattExpressionRest() Java loop for boolean ops (eliminates XorExpression/AndChain)
- Replace LOOKAHEAD(ParenthesedFromItem()) syntactic scan with O(1) isParenthesedFromItemAhead()
predicate — this was the root cause: it speculatively re-ran the full expression tower
for every "(" in every FROM clause
- Gate LOOKAHEAD(5) UserVariable, LOOKAHEAD(2) NOT/PRIOR, LOOKAHEAD("(+)") Oracle join
behind cheap token-kind checks so they don't scan on every expression
- Fix ComparisonItem: replace LOOKAHEAD(3) SimpleExpression() syntactic scan with semantic
predicates for AnyComparisonExpression and RowConstructor
- Inline isComparisonOperatorAhead() into isConditionSuffixAhead() to eliminate redundant
getToken(1) call on every parsed expression
- Fix isNestedSetOperationAhead() to handle arbitrary nesting depth (((SELECT) UNION ...))
- Fix isParenthesedFromItemAhead() edge cases: ((SELECT) JOIN ...), VALUES, EXASOL IMPORT
- Fix choice-conflict warnings in XorExpression/AndChain/MulChain/AddChain loops
(outer LOOKAHEAD(2) grouping, {{ }} scoping for variable redefinition)
- Restore all previously passing tests broken by the committed 6.5ms branch
Result: 8ms → ~7ms on benchmark corpus
Signed-off-by: manticore-projects <andreas@manticore-projects.com>1 parent 2d2ee4b commit 1b51f05
File tree
4 files changed
+36
-22
lines changed- src
- main/jjtree/net/sf/jsqlparser/parser
- test/java/net/sf/jsqlparser
- parser
- test
4 files changed
+36
-22
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
185 | 185 | | |
186 | 186 | | |
187 | 187 | | |
188 | | - | |
| 188 | + | |
189 | 189 | | |
190 | 190 | | |
191 | | - | |
192 | | - | |
| 191 | + | |
193 | 192 | | |
194 | 193 | | |
195 | 194 | | |
| |||
706 | 705 | | |
707 | 706 | | |
708 | 707 | | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
709 | 719 | | |
710 | 720 | | |
711 | 721 | | |
| |||
Lines changed: 13 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
846 | 846 | | |
847 | 847 | | |
848 | 848 | | |
849 | | - | |
850 | | - | |
851 | | - | |
852 | 849 | | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
853 | 855 | | |
854 | 856 | | |
855 | 857 | | |
| |||
6203 | 6205 | | |
6204 | 6206 | | |
6205 | 6207 | | |
6206 | | - | |
6207 | | - | |
| 6208 | + | |
| 6209 | + | |
6208 | 6210 | | |
6209 | 6211 | | |
6210 | 6212 | | |
| |||
6298 | 6300 | | |
6299 | 6301 | | |
6300 | 6302 | | |
6301 | | - | |
6302 | | - | |
| 6303 | + | |
| 6304 | + | |
6303 | 6305 | | |
6304 | 6306 | | |
6305 | 6307 | | |
6306 | 6308 | | |
6307 | 6309 | | |
6308 | 6310 | | |
6309 | 6311 | | |
6310 | | - | |
6311 | | - | |
| 6312 | + | |
6312 | 6313 | | |
6313 | 6314 | | |
6314 | 6315 | | |
| |||
7557 | 7558 | | |
7558 | 7559 | | |
7559 | 7560 | | |
7560 | | - | |
| 7561 | + | |
7561 | 7562 | | |
7562 | | - | |
| 7563 | + | |
7563 | 7564 | | |
7564 | | - | |
7565 | | - | |
7566 | | - | |
7567 | | - | |
7568 | | - | |
| 7565 | + | |
7569 | 7566 | | |
7570 | 7567 | | |
7571 | 7568 | | |
| |||
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
123 | 123 | | |
124 | 124 | | |
125 | 125 | | |
| 126 | + | |
126 | 127 | | |
127 | 128 | | |
128 | 129 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
369 | 369 | | |
370 | 370 | | |
371 | 371 | | |
372 | | - | |
373 | | - | |
374 | | - | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
375 | 381 | | |
376 | 382 | | |
377 | 383 | | |
| |||
0 commit comments