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

Background analysis support #1507

Merged
merged 41 commits into from
Jul 10, 2019

Conversation

savpek
Copy link
Contributor

@savpek savpek commented May 26, 2019

Implements analysis with foreground - background queues.

  • Foreground: file you are usually currently editing, meant to be as instant as possible.
  • Backgound: optimized for project sized analysis work, meant to analysis project / hole solution in backgound.

Added event of project analyzed which can be used to notify that theres more background results available. VScode current fetch is based on editor actions -> they really don't know when more data is available.

Gives faster feedback during (initial) analysis (omnisharp-roslyn codes during startup):

Old:
before-bg-analysis-speed

New:
with-bg-analysis-speed2

Add re-analyze api for omnisharp that can be used to trigger either project or all scoped analysis:

image

When ever diagnostics are not based "calculate everything for every request (which is expensive if theres anything more than simple semantic diagnostics)" we face following problem: how to know when we need to diagnose other files that may have references to current directly or indirectly, for example in case of manual rename of interface (this is true on current LSP implementation too i think). Adds manual option to work with that problem. Even after some sophisticated logic is added theres very tricky cases like change git branches that can modify things in very crazy way and make things offsync -> this manual option is likely needed anyway.

reanalyze-project

Do anyone know does roslyn expose api to figure those indirect refences out? cc: @rchande @filipw @david-driscoll @mholo65

Current perf:
Original diagnostic solution without analyzer get diagnostics from all files every time, for that reason it linearly scales up when solution is bigger. Heres perf comparison with omnisharp code base:
perf-without-analyzers2

With analyzers (no background work running):
perf-with-analyzers

With version (analyzers enabled) that doesn't cause pressure of diagnostic fetch api (updated on vscode side) on every change, instead if is based on project events:
perf-with-analyzers2

With further optimizations analyzer enabled version are getting close to get par with original version.

Perf is currently better with analyzers enabled when project get large. In VScode this is currently worked around by flag that limits fetching all diagnostics if there is over 1000 files (configurable). However with that you cannot get errors from all files. I think similar flag should be added to analyzer too and what it does is that it doesn't trigger initial full solution analysis on startup, however it can be invoked manually -> get good from both worlds when working with larger projects.

Ready for review @rchande @filipw @mholo65 @david-driscoll

@loligans
Copy link

Is there something that is preventing this PR from going through? It seems like a really hot feature to have.

@loligans
Copy link

Is there a way I can take this for a test @savpek? I'm using VSCode.

@savpek
Copy link
Contributor Author

savpek commented Jun 20, 2019

You can setup vscode with dotnet/vscode-csharp#3089 (build vsix plugin from branch and install it to vscode) and configure "omnisharp.path" to omnisharp-roslyn version built from this PR.

One of new tests has been broken in mac for some reason for several builds, have to check it out before this is ready. Otherwise this PR is good to go in my mind, but theres new API and events in this PR so feedback/reviewers are really needed 😄

Vscode side requires tests, otherwise it is ready i think.

@savpek
Copy link
Contributor Author

savpek commented Jun 27, 2019

@david-driscoll fixed test

Copy link
Member

@david-driscoll david-driscoll left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@savpek thanks for the great pull request yet again!

I just have the one comment about maybe using a blocking collection (or a few of them looking at the code), however I'm fine without that as well.

@filipw, @rchande, @DustinCampbell (if you have time 😄 ) let me know your guys thoughts.


public AnalyzerWorkQueue(ILoggerFactory loggerFactory, Func<DateTime> utcNow = null, int timeoutForPendingWorkMs = 15*1000)
public AnalyzerWorkQueue(ILoggerFactory loggerFactory, Func<DateTime> utcNow = null, int timeoutForPendingWorkMs = 15 * 1000)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this timeout be configurable in omnisharp.json?

Copy link
Contributor Author

@savpek savpek Jun 28, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In previous version i think it could, but now in this version it only applies to request for diagnostics from single file. It's basically just failsafe to prevent api hang in this version.

However i am not sure is this needed any more at all since theres timeout for file analysis too on worker side which should prevent that situation. Timeout for single file analysis in worker could indeed be configurable and that way it's implemented only on single location.

@savpek
Copy link
Contributor Author

savpek commented Jun 28, 2019

Thanks for feedback. On trip for week now but i will fix raised issues after that 😄

@savpek
Copy link
Contributor Author

savpek commented Jul 7, 2019

Added new configuration DocumentAnalysisTimeoutMs which controls how long is timeout of single document analysis. Now queue timeout which is assertion after this PR is that * 3. And this gives possiblity to control timeout for analysis instead of hard coded 10 seconds.

@savpek
Copy link
Contributor Author

savpek commented Jul 7, 2019

Ready for re-review @david-driscoll @filipw

Copy link
Member

@david-driscoll david-driscoll left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@filipw filipw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM :shipit:

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.

4 participants