-
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
Reduce thread contention on ProjectSystemProject._gate #72424
Reduce thread contention on ProjectSystemProject._gate #72424
Conversation
This semaphore is being flagged by thread watson here: https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1881089 1) Modify CreateBatchScope to async so callers need not block the calling thread 2) Modify CreateBatchScope to take in a CancellationToken
@@ -282,5 +289,8 @@ public void RemoveAnalyzerConfigFile(string filePath) | |||
=> _projectSystemProject.RemoveAnalyzerConfigFile(filePath); | |||
|
|||
public IAsyncDisposable CreateBatchScope() => _projectSystemProject.CreateBatchScope(); | |||
|
|||
public async ValueTask<IAsyncDisposable> CreateBatchScopeAsync(CancellationToken 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.
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.
After talking with Drew, the assumption is that CPS can be modified to just use CreateBatchScopeAsync. I'll try to get a frankenbuild on my machine with the changes in CPS to test against this PR and will wait to elevate out of draft status until
- I can at least verify the behavior based on the frankenbuild.
- Both Cyrus/Drew have had a chance to look at the core idea here.
…ead utilize CreateBatchScopeAsync 2) Switch over remaining CreateBatchScope calls to CreateBatchScopeAsync inside Roslyn 3) Switch over existing (Start/End) batch calls in Roslyn and tests to CreateBatchScopeAsync
Note that I am able to get a bit of data from the dmp in the cab file, it looks like there is just a long running method while holding onto the _gate. Will talk with Cyrus about this a bit but it's really orthogonal to the work in this PR.
|
@@ -73,6 +74,7 @@ internal interface IWorkspaceProjectContext : IDisposable | |||
|
|||
void StartBatch(); | |||
IAsyncDisposable CreateBatchScope(); |
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.
possibly deprecate.
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.
Ditto for EndBatchAsync
.
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 added a comment in commit 3 that indicates all three methods that I think can be removed once the managed project system stops consuming them.
using (await _gate.DisposableWaitAsync(cancellationToken).ConfigureAwait(false)) | ||
{ | ||
_activeBatchScopes++; | ||
return new BatchScope(this); |
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.
Looks like we could thread the cancellation token through BatchScope
to its Dispose
/DisposeAsync
methods, where those methods call OnBatchScopeDisposedMaybeAsync
(which also awaits on the gate).
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.
Talked with Cyrus and we'll go ahead and give it a go
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.
Actually, I think I'm going to pass on this after looking into it a bit more. Previously, the Dispose method would always fully execute, regardless of whether cancellation had occurred. I don't think that should be changed.
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.
Fair enough. FWIW cancellation should only trigger from CPS projects when the project is being unloaded, at which point it's great to just bail immediately as everything will be torn down, but as a general mechanism it's safer to ensure a tidy disposal.
Elevating out of draft status. I tried my best to get a frankenbuild to work, but I just kept hitting too many issues trying to get the managed project system code to consume a new roslyn package |
Fixes https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1881089 Roslyn recently introduced async API for obtaining and releasing "batch" objects for applying updates in dotnet/roslyn#72424. This change increases the package versions, uses the newer API, fixes some obsolete usages, and gets things building by adding a few package references in order to break the tie on some assembly version conflicts during build. This is another iteration of dotnet#9455, which was reverted due to issues it created during signing. Unlike that prior PR, this does not remove Microsoft.VisualStudio.Internal.MicroBuild.Swix`, so I expct the same issues about duplicated items to appear.
Fixes https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1881089 Roslyn recently introduced async API for obtaining and releasing "batch" objects for applying updates in dotnet/roslyn#72424. This change increases the package versions, uses the newer API, fixes some obsolete usages, and gets things building by adding a few package references in order to break the tie on some assembly version conflicts during build. This is another iteration of dotnet#9455, which was reverted due to issues it created during signing. Unlike that prior PR, this does not remove Microsoft.VisualStudio.Internal.MicroBuild.Swix`, so I expct the same issues about duplicated items to appear.
This semaphore is being flagged by thread watson here: https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1881089