dotnet / vscode-csharp

Official C# support for Visual Studio Code
MIT License
2.83k stars 659 forks source link

How to troubleshoot slow performance? #4598

Open superman-lopez opened 3 years ago

superman-lopez commented 3 years ago

Issue Description

For a very long time (2 years+) the performance of OmniSharp has been bad on my machine (iMac 5k 2017, 3.4 GHz Quad-Core Intel Core i5 with 24GB memory). Actions take a long time, and also often time out. I have tried to troubleshoot it a few times; reinstalling extensions, SDK, vs code, etc. Sometimes by restarting OmniSharp the performance improves, but in the last months that hasn't helped either.

Very early on, I disabled the References Code Lens which did have a positive effect on its performance. I don't believe I changed other settings. I have also disabled most other extensions to make sure they are not conflicting (such as "Better Comments"). The project also includes an Angular SPA client, which folder I have excluded using <DefaultItemExcludes>$(DefaultItemExcludes);$(SpaRoot)**</DefaultItemExcludes> in my .csproj file.

Bad performance affects all functionality: renaming properties, auto creating methods or adding new parameters to existing methods, adding namespace references, compile time errors etc. Performance is better on smaller projects, but not good either.

As a reference on the machine performance: when I refactor anything in my Angular SPA Typescript code it is always instant. Even though number of lines of code and source files between the two code bases is comparable. I don't have another machine to try the same projects and compare performance. However, I do access the same machine through ms-vscode-remote and then the performance is identical.

What can I do to troubleshoot this?

Steps to Reproduce

As an example:

string testField = "Value 1";
testField = "Value2";

A simple local field, all references are shown in the code snippet. Rename from testField to testField2.

Expected Behavior

Renaming the field should be near instant.

Actual Behavior

Renaming took over 25 seconds.

Logs

OmniSharp log

_The following shows after renaming the simple field as per above code snippet:_ [fail]: OmniSharp.MSBuild.ProjectLoadListener Unexpected exception got thrown from project load listener: System.NullReferenceException: Object reference not set to an instance of an object at OmniSharp.MSBuild.ProjectLoadListener.GetSdkVersion (OmniSharp.MSBuild.Notification.ProjectLoadedEventArgs args) [0x0000b] in :0 at OmniSharp.MSBuild.ProjectLoadListener.ProjectLoaded (OmniSharp.MSBuild.Notification.ProjectLoadedEventArgs args) [0x0001a] in :0 Received response for /completion/resolve but could not find request. Received response for /v2/getcodeactions but could not find request.

C# log

C# log shows no output

Environment information

VSCode version: 1.56.2 C# Extension: 1.23.12

Mono Information OmniSharp using built-in mono
Dotnet Information .NET Core SDK (reflecting any global.json): Version: 3.1.409 Commit: 217439b5ae Runtime Environment: OS Name: Mac OS X OS Version: 10.16 OS Platform: Darwin RID: osx.10.16-x64 Base Path: /usr/local/share/dotnet/sdk/3.1.409/ Host (useful for support): Version: 3.1.15 Commit: dc339bd0fb .NET Core SDKs installed: 3.1.409 [/usr/local/share/dotnet/sdk] .NET Core runtimes installed: Microsoft.AspNetCore.App 3.1.15 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.NETCore.App 3.1.15 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] To install additional .NET Core runtimes or SDKs: https://aka.ms/dotnet-download
Visual Studio Code Extensions |Extension|Author|Version| |---|---|---| |csharp|ms-dotnettools|1.23.12| |git-graph|mhutchie|1.30.0| |remote-ssh|ms-vscode-remote|0.65.4| |remote-ssh-edit|ms-vscode-remote|0.65.6| |spellright|ban|3.0.58|
jfacoustic commented 2 years ago

Bump

Ghostbird commented 1 year ago

Are there any ways we can get comprehensive info on a possible cause for this. Recently it's become so unbearable, that it's literally faster for me to look up the docs of whatever library I'm using online, to know what properties exist on a class.

Sometimes an Omnisharp request seems served from a cache and is fast, but most requests simply take a few minutes and then time out.

Ghostbird commented 1 year ago

Any help for this? Trying to do C# development is really good if you want to become more patient. Though I'm not sure if that refers to the virtue, or the asylum.

Almost every action in omnisharp times-out and throws a TaskCanceledException and for the rest it will constant log heaps of:

Received response for X but could not find request.

igbenic commented 1 year ago

Impossibly slow for a long time

superman-lopez commented 1 year ago

I have disabled the Diagnostic Analysis by setting below setting to 25 files. It does mean I typically find broken references only during build time, but that's better than the horrendous performance I was getting.

"csharp.maxProjectFileCountForDiagnosticAnalysis": 25