Commit ae05609
committed
internal/lsp/cache: add an LRU parse cache
As work proceeds on incremental type-checking, two observations have
emerged from benchmarking:
- Using a global FileSet is impossible, as IImportShallow allocates a
large number of new token.Files (in early experiments 75%+ of in-use memory
was consumed by the FileSet!)
- Several benchmarks regressed with incremental type-checking due to
re-parsing package files following a change. Ideally after a single file
changes we would be able to re-typecheck packages containing that file
after only re-parsing the single file that changed.
These observations are in tension: because type-checking requires that
parsed ast.Files live in the same token.FileSet as the type-checked
package, we cannot naively save the results of parsing and still use a
package-scoped FileSet.
This CL seeks to address both observations, by introducing a new
mechanism for caching parsed files (a parseCache) that parses files in a
standalone FileSet offset to avoid collision with other parsed files.
This cache exposes a batch API to parse multiple files and return a
FileSet describing all of them.
Benchmarking indicates that this partially mitigates performance
regressions without sacrificing the memory improvement we by avoiding a
global cache of parsed files.
In this CL the parse cache is not yet integrated with type-checking, but
replaces certain call-sites where we previously tried to avoid parsing
through the cache.
For golang/go#57987
Change-Id: I840cf003db835a40721f086abcc7bf00486b8108
Reviewed-on: https://go-review.googlesource.com/c/tools/+/469858
Reviewed-by: Alan Donovan <[email protected]>
TryBot-Result: Gopher Robot <[email protected]>
gopls-CI: kokoro <[email protected]>
Run-TryBot: Robert Findley <[email protected]>1 parent de54582 commit ae05609
File tree
14 files changed
+509
-119
lines changed- gopls/internal/lsp
- cache
- source
14 files changed
+509
-119
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
677 | 677 | | |
678 | 678 | | |
679 | 679 | | |
680 | | - | |
| 680 | + | |
681 | 681 | | |
682 | 682 | | |
683 | 683 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
203 | 203 | | |
204 | 204 | | |
205 | 205 | | |
206 | | - | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
207 | 211 | | |
208 | 212 | | |
209 | 213 | | |
| |||
446 | 450 | | |
447 | 451 | | |
448 | 452 | | |
449 | | - | |
450 | | - | |
451 | | - | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
452 | 461 | | |
453 | | - | |
454 | | - | |
455 | | - | |
456 | | - | |
457 | | - | |
458 | | - | |
| 462 | + | |
| 463 | + | |
459 | 464 | | |
460 | 465 | | |
461 | 466 | | |
462 | 467 | | |
463 | | - | |
| 468 | + | |
464 | 469 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | 31 | | |
37 | 32 | | |
38 | 33 | | |
| |||
111 | 106 | | |
112 | 107 | | |
113 | 108 | | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | 109 | | |
131 | 110 | | |
132 | 111 | | |
| |||
146 | 125 | | |
147 | 126 | | |
148 | 127 | | |
| 128 | + | |
| 129 | + | |
149 | 130 | | |
| 131 | + | |
| 132 | + | |
150 | 133 | | |
151 | 134 | | |
152 | 135 | | |
153 | 136 | | |
154 | 137 | | |
155 | | - | |
| 138 | + | |
156 | 139 | | |
157 | 140 | | |
158 | 141 | | |
| |||
164 | 147 | | |
165 | 148 | | |
166 | 149 | | |
167 | | - | |
| 150 | + | |
168 | 151 | | |
169 | 152 | | |
170 | 153 | | |
| |||
189 | 172 | | |
190 | 173 | | |
191 | 174 | | |
192 | | - | |
| 175 | + | |
193 | 176 | | |
194 | 177 | | |
195 | 178 | | |
| |||
202 | 185 | | |
203 | 186 | | |
204 | 187 | | |
205 | | - | |
| 188 | + | |
206 | 189 | | |
207 | 190 | | |
208 | 191 | | |
209 | 192 | | |
210 | 193 | | |
211 | | - | |
| 194 | + | |
212 | 195 | | |
213 | | - | |
| 196 | + | |
214 | 197 | | |
215 | 198 | | |
216 | 199 | | |
| |||
0 commit comments