Commit 6c9b869
committed
Strip epsilon markers and cache grammar refs on the parser
Two minor reductions in per-call work:
* Strip explicit EMPTY_RULE_ID symbols out of rule branches at grammar
build time. The parser loop would have 'continue'd over them anyway, so
removing them ahead of time lets the hot symbol loop drop the epsilon
check. Pure-epsilon branches become empty branches and still match
empty via the existing empty-children fast path.
* Cache the grammar's rules, fragment_ids, rule_names, branches_for_token,
nullable_branches, and highest_terminal_id as direct parser instance
fields so parse_recursive() no longer pays for a $this->grammar->...
double hop on every call.
* Collapse the two-step node construction (new + set_children) into a
single constructor call that takes the children array directly. This
saves a method call per allocated node (~820k across the MySQL corpus).
End-to-end parser benchmark: ~27,500 QPS -> ~28,500 QPS (+3.5%).1 parent 04191de commit 6c9b869
3 files changed
Lines changed: 61 additions & 35 deletions
File tree
- packages/mysql-on-sqlite/src/parser
Lines changed: 30 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
111 | 111 | | |
112 | 112 | | |
113 | 113 | | |
| 114 | + | |
114 | 115 | | |
115 | 116 | | |
116 | 117 | | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
117 | 147 | | |
118 | 148 | | |
119 | 149 | | |
| |||
Lines changed: 3 additions & 14 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
| 18 | + | |
19 | 19 | | |
20 | | - | |
| 20 | + | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | 30 | | |
42 | 31 | | |
43 | 32 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
17 | 26 | | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
22 | 37 | | |
23 | 38 | | |
24 | 39 | | |
| |||
36 | 51 | | |
37 | 52 | | |
38 | 53 | | |
39 | | - | |
40 | 54 | | |
41 | 55 | | |
42 | 56 | | |
| |||
45 | 59 | | |
46 | 60 | | |
47 | 61 | | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
53 | 66 | | |
54 | 67 | | |
55 | 68 | | |
56 | 69 | | |
57 | 70 | | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
63 | 75 | | |
64 | 76 | | |
65 | 77 | | |
| |||
70 | 82 | | |
71 | 83 | | |
72 | 84 | | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | 85 | | |
77 | 86 | | |
78 | 87 | | |
| |||
132 | 141 | | |
133 | 142 | | |
134 | 143 | | |
135 | | - | |
136 | | - | |
137 | | - | |
| 144 | + | |
138 | 145 | | |
139 | 146 | | |
0 commit comments