Skip to content
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

Adds parallel execution of background Roslyn analyzers #2312

Closed
wants to merge 16 commits into from

Conversation

DaRosenberg
Copy link
Contributor

@DaRosenberg DaRosenberg commented Dec 19, 2021

Fixes #2241

This PR builds upon the work started by @TomasEkeli in #2285 and adds some further improvements.

The original PR:

  • uses one semaphore for foreground worker and another for background worker, which could potentially use twice the configured threads when both workers are active
  • parallelizes only at the project level. This can yield a nice perf boost when there are many projects to analyze, but will be less effective when there are fewer projects (but potentially containing many files)
  • keeps the same diagnostics events (i.e. project start/stop) which, as visualized in a client like VS Code with just one status bar message at a time, has no real meaning anymore since multiple projects are now actually analyzed simultaneously

This PR addresses the above points by:

  • Parallelizing both at the project level (with no throttling) and at the document level (with throttling) to ensure the intended concurrency in both scenarios (many projects vs. few projects) while still respecting the global configured limit
  • Using a member-level semaphore for the throttling mechanism
  • Adding a new BackgroundDiagnosticStatus event (and associated model types) in addition to the existing ProjectDiagnosticStatus event. The new event is modeled around total and remaining number of documents currently being analyzed, instead of the notion of current project. An update event is emitted every 24 documents (results in reasonable frequency on most machines, could be made time-based as an improvement) allowing clients to display meaningful progress. Code for handling the new status event can eventually be added to omnisharp-vscode and other clients.
  • Retaining the old status events for backward compat with clients, "shimmed" - displays as Analyzing (23%)

This PR also parallelizes slightly more aggressively by defaulting to 75% of available processors (rather than 50%).

TomasEkeli and others added 14 commits December 2, 2021 19:22
there is now a new option in the roslyn-extensions-option:
ThreadsToUseForAnalyzers - which defaults to half the number
of processors on the machine.

there are two workers started, one for background and one for
foreground. so this *might* actually use all the cores? in my
usage it seems not to.
same logic as for the diagnostic worker with analyzers.
since it's used for diagnostic with and without analyzers the name
should reflect this
i should never try to do this stuff from github
- Parallelize at the document level instead of only at the project level (so user benefits also with few projects but many files)
- Since currently analyzing project no longer has any real meaning, add new status events to convey "analyzing n remaining files", updates every 50 documents
- Retain old status events for backward compat with clients
- Use 75% of available cores instead of half
DaRosenberg and others added 2 commits December 19, 2021 14:19
hard-coding to a number of documents (e.g. 50 or 24) will either send
updates very rarely giving large jumps, or very frequently (i.e. many
times within one percentage-point).

this change calculates how many documents correspond to 1%, and
send an event every time that has been reached. if that is less than
every 10 documents, it events on every tenth document.

this avoids unnecessary updates and updates as often as relevant.
@DaRosenberg
Copy link
Contributor Author

The improvements in this PR have been merged into the original PR #2285 - closing this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Analyzing projects is extremely slow compared to MSBuild or Visual Studio
2 participants