Commit efa0c9e
authored
Optimize parser a little (#18)
This PR adds the following:
* Optimizes the parser by caching the next lexed token
* Adds support for [tracy](https://github.com/wolfpld/tracy) (sampling
profiling doesn't work for some reason, only instrumentation)
* Adds a new more complicated benchmark in three sized: 1x, 10x, 100x,
1000x. (Typechecking doesn't work 100% in that benchmark yet so that
timing doesn't tell anything.)
Note that while the speedup is significant, the parser is still too
slow. This is likely due to the lexer being too intertwined with the
parser and too much control flow / indirection in the hot loop. The next
PR will try to extract and optimize the lexer, also hopefully
simplifying the parser logic.
Benchmarks:
```
main this PR
def_parse [ 3.8 us ... 1.4 us ] -63.30%*
def_resolve [ 925.3 ns ... 919.2 ns ] -0.66%*
def_typecheck [ 780.7 ns ... 791.9 ns ] +1.44%
def_resolve_merge [ 1.1 us ... 1.1 us ] +1.18%*
def_typecheck_merge [ 831.7 ns ... 808.0 ns ] -2.85%*
def_compile [ 5.2 us ... 2.8 us ] -46.44%*
def_nu_old [ 3.4 us ... 3.4 us ] +2.43%*
if_parse [ 5.0 us ... 1.8 us ] -63.52%*
if_resolve [ 469.7 ns ... 457.5 ns ] -2.58%*
if_typecheck [ 404.4 ns ... 414.4 ns ] +2.47%*
if_resolve_merge [ 580.7 ns ... 594.2 ns ] +2.31%*
if_typecheck_merge [ 429.4 ns ... 432.4 ns ] +0.69%*
if_compile [ 5.7 us ... 2.4 us ] -57.44%*
if_nu_old [ 5.2 us ... 5.3 us ] +1.48%*
combined_parse [ 25.2 us ... 8.3 us ] -66.96%*
combined_resolve [ 4.4 us ... 4.3 us ] -2.46%*
combined_typecheck [ 3.9 us ... 3.9 us ] +0.22%
combined_resolve_merge [ 5.0 us ... 4.8 us ] -4.29%*
combined_typecheck_merge [ 4.0 us ... 4.0 us ] +0.44%
combined_compile [ 32.3 us ... 14.8 us ] -54.11%*
combined_nu_old [ 4.2 us ... 4.3 us ] +1.93%*
combined10_parse [ 250.8 us ... 82.4 us ] -67.16%*
combined10_resolve [ 51.5 us ... 48.6 us ] -5.68%*
combined10_typecheck [ 43.2 us ... 43.8 us ] +1.41%*
combined10_resolve_merge [ 51.0 us ... 49.9 us ] -2.00%*
combined10_typecheck_merge [ 44.4 us ... 43.2 us ] -2.50%
combined10_compile [ 330.1 us ... 151.7 us ] -54.04%*
combined10_nu_old [ 39.0 us ... 39.8 us ] +1.96%*
combined100_parse [ 2.5 ms ... 748.1 us ] -69.91%*
combined100_resolve [ 480.6 us ... 476.4 us ] -0.88%
combined100_typecheck [ 435.4 us ... 451.7 us ] +3.73%
combined100_resolve_merge [ 506.0 us ... 520.9 us ] +2.93%
combined100_typecheck_merge [ 456.8 us ... 451.6 us ] -1.15%
combined100_compile [ 3.2 ms ... 1.4 ms ] -54.94%*
combined100_nu_old [ 383.4 us ... 392.0 us ] +2.24%*
combined1000_parse [ 23.9 ms ... 6.5 ms ] -72.61%*
combined1000_resolve [ 4.9 ms ... 4.7 ms ] -3.39%
combined1000_typecheck [ 4.6 ms ... 4.6 ms ] -0.20%
combined1000_resolve_merge [ 5.6 ms ... 5.4 ms ] -3.75%
combined1000_typecheck_merge [ 5.6 ms ... 5.8 ms ] +4.97%
combined1000_compile [ 31.6 ms ... 13.7 ms ] -56.69%*
combined1000_nu_old [ 3.9 ms ... 3.9 ms ] +0.56%
nu_old_empty [ 332.2 ns ... 330.2 ns ] -0.60%
```1 parent 8a6aa37 commit efa0c9e
File tree
10 files changed
+30411
-78
lines changed- benches
- nu
- src
10 files changed
+30411
-78
lines changedSome generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
9 | 23 | | |
10 | 24 | | |
11 | 25 | | |
| |||
14 | 28 | | |
15 | 29 | | |
16 | 30 | | |
17 | | - | |
18 | | - | |
| 31 | + | |
| 32 | + | |
19 | 33 | | |
20 | 34 | | |
21 | 35 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
13 | 20 | | |
14 | 21 | | |
15 | 22 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 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 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
0 commit comments