editorService & modelService refactor and optimizations
Created by: lguychard
Still a fair bit of cleanup to do here, but this introduces some significant improvements towards https://github.com/sourcegraph/sourcegraph/issues/5172.
Notable changes:
- Refactor editorService, modelService to be backed by
Map
s, rather than immutable arrays. - Emit incremental updates of added/updated/deleted editors and models, rather than a new array of all editors/models on every emission. This dramatically reduces GC pressure, and improves efficiency of adding/updating/deleting models and editors.
- Introduces
editorService.activeEditorUpdates
, to avoid needless iteration over all editors when computing context keys. - Introduces
editorService.activeLanguages
(still very rough, may move to modelService) to avoid needless iteration over all editors when computing active extensions.
All tests passed before I started working on 3. and 4.
On the 999-file PR (https://github.com/sourcegraph/sourcegraph/pull/5157/files#diff-1de4be34265b5e830d0e2a2fea7f386bR866), I was able to reliably load up to 400 code views, including blob fetching, in <90seconds. On the same PR, an extension built from master stalls after 270 code views loaded in ~5 minutes.
Merge request reports
Activity
Created by: codecov[bot]
Codecov Report
Merging #5464 into master will decrease coverage by
0.72%
. The diff coverage is78.77%
.@@ Coverage Diff @@ ## master #5464 +/- ## ========================================== - Coverage 47.79% 47.07% -0.73% ========================================== Files 752 742 -10 Lines 46170 45487 -683 Branches 2720 2623 -97 ========================================== - Hits 22068 21414 -654 + Misses 22036 22007 -29 Partials 2066 2066
Impacted Files Coverage Δ browser/src/libs/code_intelligence/text_fields.tsx 84.84% <ø> (ø)
shared/src/api/client/services.ts 100% <ø> (ø)
shared/src/extensions/controller.ts 15.87% <0%> (ø)
web/src/repo/blob/discussions/mentionCompletion.ts 40% <0%> (+11.42%)
shared/src/api/client/context/context.ts 96.66% <100%> (ø)
...src/components/editorTextField/EditorTextField.tsx 61.81% <100%> (ø)
shared/src/api/client/services/location.ts 95.45% <100%> (-0.38%)
shared/src/api/integration-test/testHelpers.ts 92.3% <100%> (+0.2%)
shared/src/api/client/services/editorService.ts 100% <100%> (+3.44%)
shared/src/api/extension/api/textDocument.ts 72.41% <37.5%> (-3.54%)
... and 20 more Created by: lguychard
Quick plot of loading 400 code views (including resolving revs / fetching file contents) on this branch vs. master:
- The extension built from
refactor-editors-models
loaded 400 code views in 49.2 seconds. - The extension built from
master
crashed the page after loading 370 code views in a little over 8 minutes.
We'll likely still need to look into using IntersectionObserver to lazily load code views, as blocking interactions with the page for ~40 seconds is not acceptable, even on very large PRs, but at least editor/model updates are reasonably efficient now.
All tests pass, I'll do another pass on the code to improve docstrings and other warts, but the general structure is unlikely to change at this stage.
- The extension built from