NuGetAbstraction.GetSdkResult could take out two thread pool threads in one call #12739
Labels
Functionality:Restore
Priority:2
Issues for the current backlog.
Product:MSBuildSDKResolver
The NuGet powered SDK resolver. Owned by MSBuild team
Product:VS.Client
Tenet:Performance
Performance issues
Type:Bug
NuGet Product Used
Other/NA
Product Version
Visual Studio 17.6
Worked before?
No response
Impact
Other
Repro Steps & Context
The function is written in a way that it could take out two thread pool threads in one single call. Here is the problematic piece:
This call to use Task.Result is generally forbidden inside VS, as it can easily cause deadlocks on UI thread. (The generally pattern is calling JTF.Run and await the task inside it.
When the function is called on the thread pool. This pattern can lead poor performance as:
1, Task.Run would queue the work in the current thread pool queue
2, when the code runs into Task.Result, it blocks the current thread, so it will stop processing any other pending work.
3, generally, the other thread pool thread takes work in the priority order of its own queue, then the global queue, and when both empty, it looks for each other's private queue.
So, the code pattern would lead the thread to be blocked, until the condition of another thread pool thread happens to have no other work to do to start the Restore task. This can lead a much longer delay, when many other works are queued in the thread pool.
as the comment in the code, the Task.Run is a workaround to address the problem when this function is called on the UI thread, so we should remove this workaround when the function is not called on the UI thread, especially on the thread pool.
Verbose Logs
No response
The text was updated successfully, but these errors were encountered: