Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize module resolution cache for watch and editor #37055

Merged
merged 3 commits into from
Mar 11, 2020

Conversation

sheetalkamat
Copy link
Member

@sheetalkamat sheetalkamat commented Feb 26, 2020

Before this change we had few issues with the resolution cache.. It only stored resolutions per file. So when something changed we had to go through map and invalidate the resolutions in each file based on what changed. Because earlier resolution was readonly only object with resolution and failed lookup locations, every resolution is distinct even when resolution in say file "/a/b/c.ts" was reused as resolution from file /a/b/x/d.ts. The difference was that the later resolution would contain more failed lookup locations but everything else will be same. Given the number of resolutions to go through to invalidate them, we use to skip going through resolutions and just re-evaluate them when asked for if program contained more than 256 files. So there was lot of time spent in module resolution on rename of files or some such updates..

This PR makes below changes:

  1. This makes resolutions's failed lookup locations as non readonly array so we can append more failed lookup locations to already present resolution. This also returns same resolution instead of copying the content so we have less number of unique resolutions.
  2. Resolutions with failed lookup locations are stored in separate array so its easier to scan through and invalidate them (since that number is lower compared to number of unique resolutions. In case of vscode 475 resolutions with failed lookup locations compared to 13923 unique resolutions)
  3. We also have a map that is from file the resolution is resolved to. (The max number in this case are 322 in vscode scenario.) Again this makes it easy to invalidate resolutions resolving to certain file.

Here are the number of resolutions for vscode source and rename action in repro
Note that ResolutionsToFile I am listing files only if number of resolutions are more than 100 to that file otherwise list gets long...
Note that vscode has 2227 files in the project

Initial Project creation::
Info 2284 [14:8:43.613] ResolutionCache:: module:: Number of unique  resolutions: 13923
Info 2285 [14:8:43.613] ResolutionCache:: module:: Number of loaderInvokes: 14305
Info 2286 [14:8:43.613] ResolutionCache:: typeRef:: Number of unique  resolutions: 13
Info 2287 [14:8:43.613] ResolutionCache:: typeRef:: Number of loaderInvokes: 13
Info 2288 [14:8:43.613] ResolutionCache:: Resolutions with failedLookups:: 475
Info 2289 [14:8:43.615] ResolutionCache:: ResolutionsToFile: c:/github/vscode/src/vs/base/common/lifecycle.ts:: 322
Info 2290 [14:8:43.615] ResolutionCache:: ResolutionsToFile: c:/github/vscode/src/vs/base/common/uri.ts:: 293
Info 2291 [14:8:43.615] ResolutionCache:: ResolutionsToFile: c:/github/vscode/src/vs/base/common/event.ts:: 269
Info 2292 [14:8:43.615] ResolutionCache:: ResolutionsToFile: c:/github/vscode/src/vs/platform/instantiation/common/instantiation.ts:: 242
Info 2293 [14:8:43.615] ResolutionCache:: ResolutionsToFile: c:/github/vscode/src/vs/nls.d.ts:: 216
Info 2294 [14:8:43.615] ResolutionCache:: ResolutionsToFile: c:/github/vscode/src/vs/base/common/platform.ts:: 197
Info 2295 [14:8:43.615] ResolutionCache:: ResolutionsToFile: c:/github/vscode/src/vs/base/common/async.ts:: 159
Info 2296 [14:8:43.615] ResolutionCache:: ResolutionsToFile: c:/github/vscode/src/vs/platform/configuration/common/configuration.ts:: 146
Info 2297 [14:8:43.615] ResolutionCache:: ResolutionsToFile: c:/github/vscode/src/vs/platform/files/common/files.ts:: 130
Info 2298 [14:8:43.615] ResolutionCache:: ResolutionsToFile: c:/github/vscode/src/vs/editor/common/model.ts:: 129
Info 2299 [14:8:43.615] ResolutionCache:: ResolutionsToFile: c:/github/vscode/src/vs/base/browser/dom.ts:: 126
Info 2300 [14:8:43.615] ResolutionCache:: ResolutionsToFile: c:/github/vscode/src/vs/base/common/path.ts:: 126
Info 2301 [14:8:43.615] ResolutionCache:: ResolutionsToFile: c:/github/vscode/src/vs/platform/registry/common/platform.ts:: 126
Info 2302 [14:8:43.615] ResolutionCache:: ResolutionsToFile: c:/github/vscode/src/vs/base/common/strings.ts:: 125
Info 2303 [14:8:43.615] ResolutionCache:: ResolutionsToFile: c:/github/vscode/src/vs/platform/instantiation/common/extensions.ts:: 125
Info 2304 [14:8:43.615] ResolutionCache:: ResolutionsToFile: c:/github/vscode/src/vs/base/common/types.ts:: 124
Info 2305 [14:8:43.615] ResolutionCache:: ResolutionsToFile: c:/github/vscode/src/vs/base/common/arrays.ts:: 123
Info 2306 [14:8:43.615] ResolutionCache:: ResolutionsToFile: c:/github/vscode/src/vs/platform/log/common/log.ts:: 122
Info 2307 [14:8:43.616] ResolutionCache:: ResolutionsToFile: c:/github/vscode/src/vs/editor/common/core/range.ts:: 120
Info 2308 [14:8:43.616] ResolutionCache:: ResolutionsToFile: c:/github/vscode/src/vs/platform/theme/common/themeservice.ts:: 119
Info 2309 [14:8:43.616] ResolutionCache:: ResolutionsToFile: c:/github/vscode/src/vs/base/common/cancellation.ts:: 118
Info 2310 [14:8:43.616] ResolutionCache:: ResolutionsToFile: c:/github/vscode/src/vs/base/common/resources.ts:: 117
Info 2311 [14:8:43.616] ResolutionCache:: ResolutionsToFile: c:/github/vscode/src/vs/platform/contextkey/common/contextkey.ts:: 117
Info 2312 [14:8:43.616] ResolutionCache:: ResolutionsToFile: c:/github/vscode/src/vs/base/common/keycodes.ts:: 116
Info 2313 [14:8:43.616] ResolutionCache:: ResolutionsToFile: c:/github/vscode/src/vs/editor/common/modes.ts:: 105
Info 2314 [14:8:43.616] ResolutionCache:: ResolutionsToFile: c:/github/vscode/src/vs/base/common/network.ts:: 103
Info 2315 [14:8:43.616] ResolutionCache:: ResolutionsToFile: c:/github/vscode/src/vs/platform/telemetry/common/telemetry.ts:: 103
Info 2316 [14:8:43.616] ResolutionCache:: ResolutionsToFile: c:/github/vscode/src/vs/editor/common/config/editoroptions.ts:: 101



Rename::
Watch invoked for creation of codeActionRenamed:: (timeout to update vscode config file)
Info 4170 [14:14:42.368] ResolutionCache:: module:: Number of unique  resolutions: 16
Info 4171 [14:14:42.368] ResolutionCache:: module:: Number of loaderInvokes: 22
Info 4172 [14:14:42.368] ResolutionCache:: typeRef:: Number of unique  resolutions: 0
Info 4173 [14:14:42.368] ResolutionCache:: typeRef:: Number of loaderInvokes: 0
Info 4174 [14:14:42.368] ResolutionCache:: Resolutions with failedLookups:: 477
Info 4175 [14:14:42.371] ResolutionCache:: ResolutionsToFile: c:/github/vscode/src/vs/base/common/lifecycle.ts:: 323
Info 4176 [14:14:42.371] ResolutionCache:: ResolutionsToFile: c:/github/vscode/src/vs/base/common/uri.ts:: 294
Info 4177 [14:14:42.371] ResolutionCache:: ResolutionsToFile: c:/github/vscode/src/vs/base/common/event.ts:: 269
Info 4178 [14:14:42.371] ResolutionCache:: ResolutionsToFile: c:/github/vscode/src/vs/platform/instantiation/common/instantiation.ts:: 242
Info 4179 [14:14:42.371] ResolutionCache:: ResolutionsToFile: c:/github/vscode/src/vs/nls.d.ts:: 216
Info 4180 [14:14:42.371] ResolutionCache:: ResolutionsToFile: c:/github/vscode/src/vs/base/common/platform.ts:: 197
Info 4181 [14:14:42.371] ResolutionCache:: ResolutionsToFile: c:/github/vscode/src/vs/base/common/async.ts:: 159
Info 4182 [14:14:42.371] ResolutionCache:: ResolutionsToFile: c:/github/vscode/src/vs/platform/configuration/common/configuration.ts:: 146
Info 4183 [14:14:42.371] ResolutionCache:: ResolutionsToFile: c:/github/vscode/src/vs/platform/files/common/files.ts:: 130
Info 4184 [14:14:42.371] ResolutionCache:: ResolutionsToFile: c:/github/vscode/src/vs/editor/common/model.ts:: 129
Info 4185 [14:14:42.371] ResolutionCache:: ResolutionsToFile: c:/github/vscode/src/vs/base/browser/dom.ts:: 126
Info 4186 [14:14:42.371] ResolutionCache:: ResolutionsToFile: c:/github/vscode/src/vs/base/common/path.ts:: 126
Info 4187 [14:14:42.372] ResolutionCache:: ResolutionsToFile: c:/github/vscode/src/vs/platform/registry/common/platform.ts:: 126
Info 4188 [14:14:42.372] ResolutionCache:: ResolutionsToFile: c:/github/vscode/src/vs/base/common/strings.ts:: 125
Info 4189 [14:14:42.372] ResolutionCache:: ResolutionsToFile: c:/github/vscode/src/vs/platform/instantiation/common/extensions.ts:: 125
Info 4190 [14:14:42.372] ResolutionCache:: ResolutionsToFile: c:/github/vscode/src/vs/base/common/types.ts:: 124
Info 4191 [14:14:42.372] ResolutionCache:: ResolutionsToFile: c:/github/vscode/src/vs/base/common/arrays.ts:: 124
Info 4192 [14:14:42.372] ResolutionCache:: ResolutionsToFile: c:/github/vscode/src/vs/platform/log/common/log.ts:: 122
Info 4193 [14:14:42.372] ResolutionCache:: ResolutionsToFile: c:/github/vscode/src/vs/editor/common/core/range.ts:: 121
Info 4194 [14:14:42.372] ResolutionCache:: ResolutionsToFile: c:/github/vscode/src/vs/platform/theme/common/themeservice.ts:: 119
Info 4195 [14:14:42.372] ResolutionCache:: ResolutionsToFile: c:/github/vscode/src/vs/base/common/cancellation.ts:: 118
Info 4196 [14:14:42.372] ResolutionCache:: ResolutionsToFile: c:/github/vscode/src/vs/base/common/resources.ts:: 117
Info 4197 [14:14:42.372] ResolutionCache:: ResolutionsToFile: c:/github/vscode/src/vs/platform/contextkey/common/contextkey.ts:: 117
Info 4198 [14:14:42.372] ResolutionCache:: ResolutionsToFile: c:/github/vscode/src/vs/base/common/keycodes.ts:: 116
Info 4199 [14:14:42.372] ResolutionCache:: ResolutionsToFile: c:/github/vscode/src/vs/editor/common/modes.ts:: 106
Info 4200 [14:14:42.372] ResolutionCache:: ResolutionsToFile: c:/github/vscode/src/vs/base/common/network.ts:: 103
Info 4201 [14:14:42.372] ResolutionCache:: ResolutionsToFile: c:/github/vscode/src/vs/platform/telemetry/common/telemetry.ts:: 103
Info 4202 [14:14:42.372] ResolutionCache:: ResolutionsToFile: c:/github/vscode/src/vs/base/common/errors.ts:: 101
Info 4203 [14:14:42.372] ResolutionCache:: ResolutionsToFile: c:/github/vscode/src/vs/editor/common/config/editoroptions.ts:: 101

UpdateOpen call::
To close codeAction and open renamed file
No Resolutions:: or updates(because timeout happened before)

Open with all the edits::
Info 6358 [14:14:45.215] ResolutionCache:: module:: Number of unique  resolutions: 8
Info 6359 [14:14:45.215] ResolutionCache:: module:: Number of loaderInvokes: 8
Info 6360 [14:14:45.215] ResolutionCache:: typeRef:: Number of unique  resolutions: 0
Info 6361 [14:14:45.215] ResolutionCache:: typeRef:: Number of loaderInvokes: 0
Info 6362 [14:14:45.215] ResolutionCache:: Resolutions with failedLookups:: 475
Info 6363 [14:14:45.216] ResolutionCache:: ResolutionsToFile: c:/github/vscode/src/vs/base/common/lifecycle.ts:: 323
Info 6364 [14:14:45.216] ResolutionCache:: ResolutionsToFile: c:/github/vscode/src/vs/base/common/uri.ts:: 294
Info 6365 [14:14:45.216] ResolutionCache:: ResolutionsToFile: c:/github/vscode/src/vs/base/common/event.ts:: 269
Info 6366 [14:14:45.216] ResolutionCache:: ResolutionsToFile: c:/github/vscode/src/vs/platform/instantiation/common/instantiation.ts:: 242
Info 6367 [14:14:45.216] ResolutionCache:: ResolutionsToFile: c:/github/vscode/src/vs/nls.d.ts:: 216
Info 6368 [14:14:45.216] ResolutionCache:: ResolutionsToFile: c:/github/vscode/src/vs/base/common/platform.ts:: 197
Info 6369 [14:14:45.216] ResolutionCache:: ResolutionsToFile: c:/github/vscode/src/vs/base/common/async.ts:: 159
Info 6370 [14:14:45.216] ResolutionCache:: ResolutionsToFile: c:/github/vscode/src/vs/platform/configuration/common/configuration.ts:: 146
Info 6371 [14:14:45.216] ResolutionCache:: ResolutionsToFile: c:/github/vscode/src/vs/platform/files/common/files.ts:: 130
Info 6372 [14:14:45.216] ResolutionCache:: ResolutionsToFile: c:/github/vscode/src/vs/editor/common/model.ts:: 129
Info 6373 [14:14:45.216] ResolutionCache:: ResolutionsToFile: c:/github/vscode/src/vs/base/browser/dom.ts:: 126
Info 6374 [14:14:45.216] ResolutionCache:: ResolutionsToFile: c:/github/vscode/src/vs/base/common/path.ts:: 126
Info 6375 [14:14:45.216] ResolutionCache:: ResolutionsToFile: c:/github/vscode/src/vs/platform/registry/common/platform.ts:: 126
Info 6376 [14:14:45.216] ResolutionCache:: ResolutionsToFile: c:/github/vscode/src/vs/base/common/strings.ts:: 125
Info 6377 [14:14:45.216] ResolutionCache:: ResolutionsToFile: c:/github/vscode/src/vs/platform/instantiation/common/extensions.ts:: 125
Info 6378 [14:14:45.216] ResolutionCache:: ResolutionsToFile: c:/github/vscode/src/vs/base/common/types.ts:: 124
Info 6379 [14:14:45.216] ResolutionCache:: ResolutionsToFile: c:/github/vscode/src/vs/base/common/arrays.ts:: 124
Info 6380 [14:14:45.216] ResolutionCache:: ResolutionsToFile: c:/github/vscode/src/vs/platform/log/common/log.ts:: 122
Info 6381 [14:14:45.216] ResolutionCache:: ResolutionsToFile: c:/github/vscode/src/vs/editor/common/core/range.ts:: 121
Info 6382 [14:14:45.216] ResolutionCache:: ResolutionsToFile: c:/github/vscode/src/vs/platform/theme/common/themeservice.ts:: 119
Info 6383 [14:14:45.216] ResolutionCache:: ResolutionsToFile: c:/github/vscode/src/vs/base/common/cancellation.ts:: 118
Info 6384 [14:14:45.216] ResolutionCache:: ResolutionsToFile: c:/github/vscode/src/vs/base/common/resources.ts:: 117
Info 6385 [14:14:45.216] ResolutionCache:: ResolutionsToFile: c:/github/vscode/src/vs/platform/contextkey/common/contextkey.ts:: 117
Info 6386 [14:14:45.216] ResolutionCache:: ResolutionsToFile: c:/github/vscode/src/vs/base/common/keycodes.ts:: 116
Info 6387 [14:14:45.216] ResolutionCache:: ResolutionsToFile: c:/github/vscode/src/vs/editor/common/modes.ts:: 106
Info 6388 [14:14:45.216] ResolutionCache:: ResolutionsToFile: c:/github/vscode/src/vs/base/common/network.ts:: 103
Info 6389 [14:14:45.216] ResolutionCache:: ResolutionsToFile: c:/github/vscode/src/vs/platform/telemetry/common/telemetry.ts:: 103
Info 6390 [14:14:45.216] ResolutionCache:: ResolutionsToFile: c:/github/vscode/src/vs/base/common/errors.ts:: 101
Info 6391 [14:14:45.216] ResolutionCache:: ResolutionsToFile: c:/github/vscode/src/vs/editor/common/config/editoroptions.ts:: 101

This fixes #30535

@amcasey
Copy link
Member

amcasey commented Mar 6, 2020

The idea seems sensible, but I would find a high-level overview of the cache structure helpful.

@sheetalkamat
Copy link
Member Author

While investigating eslint perf with @uniqueiniquity found out that this helps with eslint when the program contains large number of files

@sheetalkamat
Copy link
Member Author

@amcasey
The description already has two data structures added as part of point 2 and 3. Ping me if you have any questions..

Copy link
Member

@amcasey amcasey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea makes sense and the implementation looks sane.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

getEditsForFileRename taking long time
3 participants