unclebob/fitnesse — pull request #255 by stanio (2013-04-29 09:14:55+00:00)
Title: Optimize parser performance

I've gathered basic statistics about the `Symbol` creation and I've got:
```
!| Symbol Name | Max Children | Usage Rate |
| Whitespace | 0 | 0.319157 |
| Text | 0 | 0.236232 |
| SymbolList | 932 | 0.156875 |
| EndCell | 0 | 0.118764 |
| Newline | 0 | 0.049753 |
| CloseBracket | 0 | 0.027596 |
| CloseBrace | 0 | 0.021700 |
| OpenBracket | 0 | 0.013395 |
| Path | 1 | 0.010051 |
| Variable | 2 | 0.009809 |
| Colon | 0 | 0.007823 |
| Comma | 0 | 0.005611 |
| Bold | 1 | 0.003850 |
| Delta | 0 | 0.003060 |
| Table | 302 | 0.002567 |
| HeaderLine | 1 | 0.001764 |
| CloseParenthesis | 0 | 0.001534 |
| Alias | 2 | 0.001520 |
| Italic | 1 | 0.001288 |
| HashTable | 13 | 0.001154 |
| CloseLiteral | 0 | 0.001071 |
| Literal | 0 | 0.001070 |
| UnorderedList | 10 | 0.001049 |
| OpenParenthesis | 0 | 0.000751 |
| Contents | 5 | 0.000600 |
| Define | 2 | 0.000525 |
| OpenBrace | 0 | 0.000396 |
| Comment | 1 | 0.000268 |
| HorizontalRule | 0 | 0.000242 |
| CloseCollapsible | 0 | 0.000146 |
| Collapsible | 2 | 0.000140 |
| AnchorName | 1 | 0.000057 |
| ClosePreformat | 0 | 0.000041 |
| WikiWord | 0 | 0.000035 |
| Include | 4 | 0.000026 |
| Preformat | 1 | 0.000021 |
| NoteLine | 1 | 0.000020 |
| AnchorReference | 1 | 0.000017 |
| OrderedList | 12 | 0.000011 |
| Strike | 0 | 0.000010 |
| Style | 1 | 0.000001 |
| Link | 1 | 0.000000 |
| Empty | 0 | 0.000000 |
```
One sees `Whitespace` and `Text` been about 55% of all `Symbol` instances, and those don't have `children` so allocating new list with default capacity of 10 for every such symbol is unnecessary wasteful.

Further `SymbolList` has reached maximum of 932 children, but getting a statistic for it alone reveals:
```
!| SymbolList |
| Children | Ratio |
| 2 | 0.237127 |
| 1 | 0.096052 |
| 3 | 0.055926 |
| 4 | 0.044992 |
| 16 | 0.042085 |
| 158 | 0.036642 |
| 9 | 0.030668 |
| 18 | 0.030595 |
| 20 | 0.025181 |
| 25 | 0.021442 |
| 12 | 0.020876 |
| 14 | 0.019214 |
| 19 | 0.018933 |
| 24 | 0.015310 |
| 5 | 0.015291 |
| 21 | 0.014975 |
| 31 | 0.014845 |
| 6 | 0.014630 |
| 10 | 0.014580 |
| 26 | 0.014450 |
| 56 | 0.014380 |
| 8 | 0.014283 |
| 17 | 0.011847 |
| 32 | 0.011382 |
| 30 | 0.010861 |
| 15 | 0.009933 |
| 7 | 0.008311 |
| 34 | 0.008278 |
| 33 | 0.006184 |
| 13 | 0.006127 |
| 28 | 0.005992 |
| 11 | 0.004867 |
| 35 | 0.004676 |
| 27 | 0.004669 |
| 22 | 0.004530 |
| 248 | 0.004016 |
| 29 | 0.003656 |
| 63 | 0.003534 |
| 37 | 0.003467 |
| 342 | 0.003165 |
| 23 | 0.003006 |
| 185 | 0.002996 |
| 330 | 0.002290 |
| 502 | 0.002032 |
| 47 | 0.001876 |
| 77 | 0.001870 |
| 40 | 0.001712 |
| 79 | 0.001462 |
| 839 | 0.001456 |
| 228 | 0.001450 |
| 48 | 0.001444 |
| 39 | 0.001398 |
| 212 | 0.001349 |
| 41 | 0.001304 |
| 731 | 0.001268 |
| 206 | 0.001191 |
| 681 | 0.001182 |
| 283 | 0.001146 |
| 492 | 0.001138 |
| 440 | 0.001018 |
| 328 | 0.000948 |
| 309 | 0.000894 |
| 306 | 0.000885 |
| 45 | 0.000885 |
| 468 | 0.000812 |
| 140 | 0.000810 |
| 82 | 0.000806 |
| 58 | 0.000805 |
| 197 | 0.000798 |
| 138 | 0.000798 |
| 124 | 0.000789 |
| 36 | 0.000770 |
| 38 | 0.000747 |
| 322 | 0.000745 |
| 44 | 0.000738 |
| 285 | 0.000659 |
| 142 | 0.000657 |
| 279 | 0.000645 |
| 50 | 0.000636 |
| 272 | 0.000629 |
| 49 | 0.000595 |
| 334 | 0.000579 |
| 500 | 0.000578 |
| 250 | 0.000578 |
| 62 | 0.000574 |
| 43 | 0.000572 |
| 932 | 0.000539 |
| 227 | 0.000525 |
| 55 | 0.000509 |
| 281 | 0.000488 |
| 280 | 0.000486 |
| 42 | 0.000486 |
| 46 | 0.000479 |
| 751 | 0.000434 |
| 249 | 0.000432 |
| 186 | 0.000430 |
| 734 | 0.000425 |
| 87 | 0.000403 |
| 139 | 0.000402 |
| 672 | 0.000389 |
| 65 | 0.000376 |
| 159 | 0.000368 |
| 78 | 0.000361 |
| 611 | 0.000353 |
| 189 | 0.000328 |
| 531 | 0.000307 |
| 530 | 0.000307 |
| 527 | 0.000305 |
| 470 | 0.000272 |
| 223 | 0.000258 |
| 109 | 0.000252 |
| 432 | 0.000250 |
| 71 | 0.000246 |
| 379 | 0.000219 |
| 377 | 0.000218 |
| 374 | 0.000216 |
| 53 | 0.000215 |
| 363 | 0.000210 |
| 362 | 0.000209 |
| 360 | 0.000208 |
| 57 | 0.000198 |
| 339 | 0.000196 |
| 333 | 0.000193 |
| 332 | 0.000192 |
| 321 | 0.000186 |
| 319 | 0.000184 |
| 318 | 0.000184 |
| 312 | 0.000180 |
| 305 | 0.000176 |
| 304 | 0.000176 |
| 301 | 0.000174 |
| 299 | 0.000173 |
| 293 | 0.000169 |
| 291 | 0.000168 |
| 72 | 0.000167 |
| 286 | 0.000165 |
| 277 | 0.000160 |
| 269 | 0.000156 |
| 268 | 0.000155 |
| 266 | 0.000154 |
| 66 | 0.000153 |
| 254 | 0.000147 |
| 85 | 0.000147 |
| 252 | 0.000146 |
| 60 | 0.000139 |
| 238 | 0.000138 |
| 232 | 0.000134 |
| 229 | 0.000132 |
| 76 | 0.000132 |
| 111 | 0.000128 |
| 74 | 0.000128 |
| 220 | 0.000127 |
| 219 | 0.000127 |
| 216 | 0.000125 |
| 54 | 0.000125 |
| 213 | 0.000123 |
| 101 | 0.000117 |
| 201 | 0.000116 |
| 193 | 0.000112 |
| 192 | 0.000111 |
| 96 | 0.000111 |
| 64 | 0.000111 |
| 187 | 0.000108 |
| 93 | 0.000108 |
| 184 | 0.000106 |
| 181 | 0.000105 |
| 170 | 0.000098 |
| 166 | 0.000096 |
| 162 | 0.000094 |
| 161 | 0.000093 |
| 160 | 0.000093 |
| 157 | 0.000091 |
| 51 | 0.000088 |
| 69 | 0.000080 |
| 68 | 0.000079 |
| 132 | 0.000076 |
| 120 | 0.000069 |
| 117 | 0.000068 |
| 59 | 0.000068 |
| 113 | 0.000065 |
| 110 | 0.000064 |
| 107 | 0.000062 |
| 105 | 0.000061 |
| 104 | 0.000060 |
| 52 | 0.000060 |
| 98 | 0.000057 |
| 97 | 0.000056 |
| 92 | 0.000053 |
| 81 | 0.000047 |
| 80 | 0.000046 |
| 73 | 0.000042 |
| 70 | 0.000040 |
| 61 | 0.000035 |
| 0 | 0.000000 |
```
So about 33% are instances which have maximum of 1 or 2 children.

The given changes try to address the above findings and few more details.