Commit 4c298c8
committed
Use FastHash on Piece.
This mixin overrides the default identity-based hash code with a stored integer hash code. That made a big difference in the old formatter's performance but for most of the times I tried it with the new one, it didn't help. But it seems that the new formatter is storing pieces in maps enough for it to make a difference.
On the microbenchmarks:
```
Benchmark (tall) fastest median slowest average baseline
----------------------------- -------- ------- ------- ------- --------
block 0.057 0.061 0.121 0.065 107.0%
chain 0.524 0.539 0.579 0.541 117.1%
collection 0.247 0.256 0.273 0.257 107.1%
collection_large 1.539 1.559 1.621 1.562 106.0%
conditional 0.060 0.061 0.079 0.062 107.0%
curry 0.455 0.462 0.477 0.463 118.0%
ffi 0.143 0.149 0.159 0.148 105.4%
flutter_popup_menu_test 0.503 0.514 0.541 0.516 115.0%
flutter_scrollbar_test 0.399 0.406 0.450 0.410 113.2%
function_call 1.658 1.709 1.849 1.716 106.0%
infix_large 0.552 0.567 0.600 0.570 108.9%
infix_small 0.145 0.148 0.162 0.149 105.3%
interpolation 0.087 0.089 0.101 0.090 102.5%
interpolation_1516 0.070 0.071 0.085 0.071 100.7%
large 3.263 3.280 3.573 3.298 109.0%
top_level 0.127 0.128 0.147 0.130 107.9%
```
And when formatting the Flutter repo:
```
Current formatter 10.138 ========================================
Optimized 9.490 =====================================
Old formatter 4.812 ==================
The current formatter is 52.54% slower than the old formatter.
The optimized is 6.83% faster than the current formatter.
The optimized is 49.29% slower than the old formatter.
The optimization gets the formatter 12.17% of the way to the old one.
```
That's pretty good for a one line change.
Also, this makes debugging the new formatter easier because now each Piece has a different debug string. Trying to figure out which of a hundred `Infix` pieces is the one you want gets pretty tedious...1 parent ecfc0cb commit 4c298c8
File tree
5 files changed
+6
-5
lines changed- lib/src
- piece
- short
- rule
5 files changed
+6
-5
lines changedFile renamed without changes.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
| |||
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
17 | | - | |
| 18 | + | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
| |||
190 | 191 | | |
191 | 192 | | |
192 | 193 | | |
193 | | - | |
| 194 | + | |
194 | 195 | | |
195 | 196 | | |
196 | 197 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
4 | 5 | | |
5 | | - | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
6 | 7 | | |
7 | 8 | | |
8 | | - | |
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| |||
0 commit comments