-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Avoid having to go back to the UI thread in the navbar code #73681
Conversation
@ToddGrun ptal |
@@ -161,26 +183,6 @@ void IDisposable.Dispose() | |||
_cancellationTokenSource.Cancel(); | |||
} | |||
|
|||
private void Pause() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
inlined these.
|
||
// Cancel any in flight work. We're on the UI thread, so we know this is the latest position of the user, and that | ||
// this should supersede any other selection work items. | ||
_selectItemQueue.AddWork(caretPoint.Value, cancelExistingWork: true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we now grab the caret and pass it along.
{ | ||
// Switch to the UI so we can determine where the user is and determine the state the last time we updated | ||
// the UI. | ||
await _threadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken).NoThrowAwaitable(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no more need to switch here.
|
||
GetProjectItems(out var projectItems, out var selectedProjectItem); | ||
var (projectItems, selectedProjectItem) = GetProjectItems(); | ||
if (Equals(model, lastPresentedInfo.model) && | ||
Equals(currentSelectedItem, lastPresentedInfo.selectedInfo) && | ||
Equals(selectedProjectItem, lastPresentedInfo.selectedProjectItem) && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in the common case (caret moving in the same member) we will bail out immediately, and not hit hte ui thread. we only need to go back if we're actually updating the UI thread.
// Once we've computed and selected the latest navbar items, pause ourselves if we're no longer visible. | ||
// That way we don't consume any machine resources that the user won't even notice. | ||
if (_visibilityTracker?.IsVisible(_subjectBuffer) is false) | ||
Pause(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this was intentionally removed. we don't need to check this here for visibility. We just listen for visbility changes directly and pause/unpause us accordingly.
language: d.Project.Language)).OrderBy(projectItem => projectItem.Text)]; | ||
language: d.Project.Language)) | ||
.OrderBy(projectItem => projectItem.Text) | ||
.ToImmutableArray(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pause(); | ||
} | ||
// Make a task that waits indefinitely, or until the cancellation token is signaled. | ||
var cancellationTriggeredTask = Task.Delay(-1, cancellationToken); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm very happy with this change. I feel like mainthread switches are an area that we've neglected in our perf efforts. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No description provided.