Skip to content

Commit 83bbaf7

Browse files
claudelalvarezt
authored andcommitted
perf(grammar): reorder pest grammar operations by usage frequency
Reorganized operation alternatives based on actual benchmark usage patterns to optimize PEG parser performance. Most frequently used operations (split, join, upper, lower, trim, substring, reverse) are now tested first.
1 parent c1e6fa5 commit 83bbaf7

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

src/pipeline/template.pest

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,31 @@ debug_flag = @{ "!" }
44

55
operation_list = { operation ~ ("|" ~ operation)* }
66

7+
// Ordered by frequency based on benchmark usage patterns
78
operation = {
89
shorthand_range
910
| shorthand_index
1011
| split
12+
| join
1113
| upper
1214
| lower
1315
| trim
14-
| append
15-
| prepend
16-
| surround
17-
| quote
18-
| join
1916
| substring
17+
| reverse
2018
| replace
21-
| map
2219
| filter
2320
| filter_not
24-
| slice
2521
| sort
26-
| reverse
2722
| unique
23+
| map
24+
| slice
25+
| append
26+
| prepend
27+
| surround
28+
| quote
29+
| pad
2830
| regex_extract
2931
| strip_ansi
30-
| pad
3132
}
3233

3334
shorthand_index = { number }
@@ -76,27 +77,28 @@ pad_char = @{ argument }
7677
// Map operation
7778
map_operation = { "{" ~ map_operation_list ~ "}" }
7879
map_operation_list = { map_inner_operation ~ ("|" ~ map_inner_operation)* }
80+
// Ordered by frequency for map operations
7981
map_inner_operation = {
80-
strip_ansi
82+
upper
83+
| lower
84+
| trim
8185
| substring
86+
| reverse
8287
| replace
88+
| map_split
89+
| map_join
8390
| append
8491
| prepend
8592
| surround
8693
| quote
87-
| upper
88-
| lower
89-
| trim
9094
| pad
91-
| reverse
92-
| map_split
93-
| map_join
9495
| map_slice
9596
| map_sort
9697
| map_unique
9798
| map_filter
9899
| map_filter_not
99100
| map_regex_extract
101+
| strip_ansi
100102
}
101103

102104
// Map-specific operations that need special handling

0 commit comments

Comments
 (0)