Skip to content

Codist causing Visual Studio responsiveness issues #215

Closed
@davkean

Description

Hey folks, I'm from the Visual Studio performance team and our telemetry is showing that Codist is causing responsiveness issues in the wild by consuming large amounts of thread pool threads.

Over the past 21 days at times where Visual Studio's thread pool has been starved, we've captured the following data:

Failure Score Cab Count Threads 90th Threads 50th Avg Threads
Codist!Unknown 16 4 28 5 12

In particular these lines are the problem:

if (cancellationToken.CanBeCanceled
&& Snapshot.Length > 1000
&& CancellableWait(Snapshot.Length > 60000 ? 100 : 30, cancellationToken) == false) {
CancelOrFault();
return Task.FromCanceled(cancellationToken);

It appears that this code is attemping to monitor the specified CancellationToken, and when triggered, cancel the parsing. When it does this, however, it consumes a thread - and in the wild, we saw that this path consumed up to 28 threads at its worst.

Instead there's an easier way to monitor cancellation and avoid the thread starvation; use CancellationToken.Register. Do however, make note, that by default the call back will run in context of the code that triggers the cancellation. If that is unwanted, and you want to maintain the existing behavior, call Register(() => {...}, useSynchronizationContext: true).

Thanks
Dave

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions