Commit b79056a
[analyzer] Don't calculate add-late assists for other files
The "add late" assist was broadened in
https://dart-review.googlesource.com/c/sdk/+/176900 with a link to
#44440 where the example is
adding `late` to a field in the same class the user is currently editing
the constructor for.
That makes sense.
The code could also add the `late` keyword to other files which is - I
think - bad for at least two reasons:
1) It's confusing being given the option to "add late" to something,
then when trying it nothing seemingly happen, except something does
happen: another - possibly not open - file has changed.
2) It requests the resolved unit for another - possibly not open -
file, which is slow. This means that, at least in VSCode, just
moving the cursor over something can send requests that takes a
long time. In practise I've experienced up to ~1.5 seconds, and in
benchmarks I can make this arbitrarily large by increasing the
size of the file. Shown below, having 16,000 small classes takes
around 4 seconds (vs less than 10 ms with this CL).
This CL restricts this to the same file, adds a few tests and updates
a few existing tests.
Note that the existing tests that verified the behavior of adding `late`
to other files was added in
https://dart-review.googlesource.com/c/sdk/+/180087 with a link to
#44534
where the issue discusses a bug where it is applied in the wrong file
and says that it should either be applied to the right file or be
disallowed. The option of allowing it was picked in that instance,
but now at least there's data to show that it comes at a cost.
For an ad-hoc test where I programmatically asks for assists at every
position in `pkg/front_end/lib/src/kernel/body_builder.dart` I go from
1875 positions that takes >= 100 ms to answer to 0 such positions.
For the added benchmark I get this data:
Before this CL:
```
size 1000:
Initial analysis: 0.188291
Action call on 4:11 : 0.308514
Action call on 4:12 : 0.319540
Action call on 4:13 : 0.274678
peak virtual memory size: 2363 MB
total program size (virtual): 2292 MB
peak resident set size ("high water mark"): 258 MB
size of memory portions (rss): 244 MB
size 2000:
Initial analysis: 0.387643
Action call on 4:11 : 0.649877
Action call on 4:12 : 0.550778
Action call on 4:13 : 0.474030
peak virtual memory size: 2325 MB
total program size (virtual): 2325 MB
peak resident set size ("high water mark"): 279 MB
size of memory portions (rss): 277 MB
size 4000:
Initial analysis: 0.753913
Action call on 4:11 : 1.086648
Action call on 4:12 : 1.015921
Action call on 4:13 : 0.915511
peak virtual memory size: 2335 MB
total program size (virtual): 2304 MB
peak resident set size ("high water mark"): 363 MB
size of memory portions (rss): 334 MB
size 8000:
Initial analysis: 1.235531
Action call on 4:11 : 1.880335
Action call on 4:12 : 1.824658
Action call on 4:13 : 1.771081
peak virtual memory size: 2414 MB
total program size (virtual): 2386 MB
peak resident set size ("high water mark"): 436 MB
size of memory portions (rss): 411 MB
size 16000:
Initial analysis: 2.618666
Action call on 4:11 : 3.991542
Action call on 4:12 : 3.775863
Action call on 4:13 : 4.094692
peak virtual memory size: 2576 MB
total program size (virtual): 2516 MB
peak resident set size ("high water mark"): 667 MB
size of memory portions (rss): 611 MB
```
With this CL:
```
size 1000:
Initial analysis: 0.202665
Action call on 4:11 : 0.005730
Action call on 4:12 : 0.003086
Action call on 4:13 : 0.002743
peak virtual memory size: 2174 MB
total program size (virtual): 2170 MB
peak resident set size ("high water mark"): 256 MB
size of memory portions (rss): 247 MB
size 2000:
Initial analysis: 0.433420
Action call on 4:11 : 0.005353
Action call on 4:12 : 0.002116
Action call on 4:13 : 0.002156
peak virtual memory size: 2226 MB
total program size (virtual): 2226 MB
peak resident set size ("high water mark"): 290 MB
size of memory portions (rss): 240 MB
size 4000:
Initial analysis: 0.674376
Action call on 4:11 : 0.004219
Action call on 4:12 : 0.002138
Action call on 4:13 : 0.001625
peak virtual memory size: 2392 MB
total program size (virtual): 2328 MB
peak resident set size ("high water mark"): 306 MB
size of memory portions (rss): 286 MB
size 8000:
Initial analysis: 1.244688
Action call on 4:11 : 0.005225
Action call on 4:12 : 0.002104
Action call on 4:13 : 0.002729
peak virtual memory size: 2349 MB
total program size (virtual): 2338 MB
peak resident set size ("high water mark"): 385 MB
size of memory portions (rss): 366 MB
size 16000:
Initial analysis: 2.776680
Action call on 4:11 : 0.008848
Action call on 4:12 : 0.002854
Action call on 4:13 : 0.002327
peak virtual memory size: 2423 MB
total program size (virtual): 2405 MB
peak resident set size ("high water mark"): 505 MB
size of memory portions (rss): 489 MB
```
It's interesting how the action calls for sizes >= 4000 was slower than
the initial analysis, but I haven't looked into it.
Change-Id: Icefe02073cdf1ad442a37de2030fd7e53f5013b9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/436280
Reviewed-by: Brian Wilkerson <[email protected]>
Commit-Queue: Jens Johansen <[email protected]>1 parent 6c7e3a6 commit b79056a
File tree
5 files changed
+194
-13
lines changed- pkg/analysis_server
- lib/src/services/correction/dart
- test/src/services/correction
- assist
- fix
- tool/benchmark_tools/single_benchmarks
5 files changed
+194
-13
lines changedLines changed: 7 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
74 | | - | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
75 | 81 | | |
76 | 82 | | |
77 | 83 | | |
| |||
Lines changed: 42 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
55 | 55 | | |
56 | 56 | | |
57 | 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 | + | |
58 | 100 | | |
59 | 101 | | |
60 | 102 | | |
| |||
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
86 | 86 | | |
87 | 87 | | |
88 | 88 | | |
| 89 | + | |
89 | 90 | | |
90 | 91 | | |
91 | 92 | | |
| |||
Lines changed: 2 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
| 36 | + | |
41 | 37 | | |
42 | 38 | | |
43 | 39 | | |
| |||
55 | 51 | | |
56 | 52 | | |
57 | 53 | | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
| 54 | + | |
65 | 55 | | |
66 | 56 | | |
67 | 57 | | |
| |||
Lines changed: 142 additions & 0 deletions
| 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 | + | |
0 commit comments