Commit 8fefbab
authored
Remove most remaining workspace changed on UI thread (#79391)
This is a reapply of #78778 that got reverted due to a potential
regression.
Commit-at-a-time is recommended, since each use gets its own commit with
further analysis there.
The remaining uses of eventing that hit the UI thread (of any kind of
workspace event) are:
1. Inline rename subscribes when there is an active rename to cancel on
changes it doesn't know about. Since this is only active during the
session, it doesn't seem worth it change it.
2. MiscellanousFilesWorkspace subscribes to workspace _registration_
changed, which is when a document is opened/closed, and that's not
urgent to fix and restricted to just registration events.
3. XamlProjectService subscribes to document _closed_. This only happens
if XAML is loaded in the first place, and then is only raised on the
close path. I looked at making a small change to move it off but the
code is generally quite scary and since it's document close only that's
not chatty.
The last commit makes a larger change for performance to avoid a
regression in our internal performance tests. To explain the change a
bit of explanation is needed:
Our WorkspaceChanged events are raised with an batching work queue with
a delay of zero. When we have events to raise on the UI thread, the
batch handler first raises the background thread notifications, then
jumps to the UI thread (if needed) and raises them there. This means
that in this case, our events are roughly 'throttled' by the
availability of the UI thread; so we're likely to end up with a flurry
of background events, then foreground events, then background events,
etc.
Usually these event handlers are feeding into other batching work
queues, including the one we use to synchronize the VS Workspace to our
OOP process to keep things relatively up to date. That had a delay of
50ms to batch up a request to start syncing it again. My belief is that
prior to the WorkspaceChanged change, that delay didn't matter so much
-- the actual batching may have been that if (say) the UI thread was
only available once every 100ms to fire events, then that was the real
rate limiting. Once that is freed up, then now we were creating a lot
more batches. I did some tests counting the number of batches during a
Roslyn solution load and it seemed to be roughly double, which matched
some of the extra allocation overhead happening in StreamJsonRpc as we
were synchronizing with OOP.
I have changed the batching delay for the OOP sync from 50ms to 250ms,
that number chosen because that's what "Short" is in our delay choices.
The excess memory allocations seen before have disappeared, making me
think we're now doing fewer but larger batches. The
ManagedLanguages.SolutionManagement RPS test shows a 10% reduction in
ServiceHub allocations than the baseline. I don't imagine this would be
particularly noticeable to a user the extra delay since that'd only
impact the final sync that happens after a solution load, which isn't
hugely critical. The immediate-sync that we have of a changed document
is left in place.File tree
8 files changed
+20
-33
lines changed- src
- EditorFeatures/Core
- Remote
- Tagging
- Features/Core/Portable/Diagnostics
- LanguageServer/Protocol/Workspaces
- VisualStudio/Core
- Def/StackTraceExplorer
- Impl/SolutionExplorer/DiagnosticItem
8 files changed
+20
-33
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
61 | 66 | | |
62 | | - | |
| 67 | + | |
63 | 68 | | |
64 | 69 | | |
65 | 70 | | |
| |||
Lines changed: 1 addition & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
17 | 16 | | |
18 | | - | |
| 17 | + | |
19 | 18 | | |
20 | 19 | | |
21 | 20 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
44 | | - | |
| 44 | + | |
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
Lines changed: 1 addition & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
52 | | - | |
53 | | - | |
54 | | - | |
| 52 | + | |
55 | 53 | | |
56 | 54 | | |
57 | 55 | | |
| |||
Lines changed: 3 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
25 | 28 | | |
26 | 29 | | |
27 | 30 | | |
| |||
Lines changed: 2 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
42 | | - | |
43 | | - | |
44 | | - | |
| 42 | + | |
45 | 43 | | |
46 | 44 | | |
47 | 45 | | |
| |||
94 | 92 | | |
95 | 93 | | |
96 | 94 | | |
97 | | - | |
98 | | - | |
99 | | - | |
| 95 | + | |
100 | 96 | | |
101 | 97 | | |
102 | 98 | | |
Lines changed: 0 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | 53 | | |
57 | 54 | | |
58 | 55 | | |
| |||
103 | 100 | | |
104 | 101 | | |
105 | 102 | | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | 103 | | |
116 | 104 | | |
117 | 105 | | |
| |||
Lines changed: 6 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| 22 | + | |
22 | 23 | | |
23 | 24 | | |
24 | 25 | | |
| |||
37 | 38 | | |
38 | 39 | | |
39 | 40 | | |
| 41 | + | |
| 42 | + | |
40 | 43 | | |
41 | 44 | | |
42 | 45 | | |
| |||
47 | 50 | | |
48 | 51 | | |
49 | 52 | | |
50 | | - | |
51 | | - | |
52 | | - | |
| 53 | + | |
53 | 54 | | |
54 | 55 | | |
55 | 56 | | |
| |||
118 | 119 | | |
119 | 120 | | |
120 | 121 | | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
| 122 | + | |
125 | 123 | | |
126 | 124 | | |
127 | 125 | | |
128 | 126 | | |
129 | | - | |
| 127 | + | |
130 | 128 | | |
131 | 129 | | |
0 commit comments