-
Notifications
You must be signed in to change notification settings - Fork 671
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
Beta: Microsoft.CodeAnalysis.LanguageServer seems to leak. #5733
Comments
I just found a very easy way to provoke the leaky behavior:
That pushes memory utilization to about 4 gb reliably for my project in a matter of seconds. Testing with other solutions I have, the rate of memory increase seems to correlate with the overall solution size. A small-ish library I have with 93 files I struggle to get over 1.4GB, even with this method. But it does leak nonetheless. |
Some additional observations: Memory utilization does actually go down, if you let VS Code sit long enough without interacting with it. But this is on the scale of hours, not minutes. Performance of the LSP does not seem to degrade much. The leaking jumps up significantly when one is reorganizing a large subsection of code. Right now I am looking at 13 GB of RAM being utilized by Edit: Since posting this update, I have left VS Code untouched. Memory usage went from 13,000mb to 12,200mb over roughly an hour. Edit number 2: Another hour later and it sits now at 10.300mb |
Don't know if exactly related, but for reproduceability: When working with C# Scripts (.csx), using dotnet-script, even toggling a comment on a single line of code in a small script will make memory consumption rise by 100MB here. |
I have a solution with about 100 projects. I've been working on it with VSCode and C# Language Extension (v1.25.9) for a few years and haven't had any problems. But after installing the C# Dev Tools extension (which updated the C# Language extension to beta) I started having the same problem of Microsoft.CodeAnalysis.LanguageServer consuming a lot of RAM (In my case 6GB+ out of 12GB) and never releasing it. Just the fact that I open vscode with 5 code tabs open, without touching anything, already increases the amount of RAM. |
I feel the same. |
To provide some actually useful info instead of just repeating that the issue exists (🙃): Since opening the issue, the leak has become less severe. It still leaks and can reach some very absurd memory utilization, but in regular working on the same repository I worked on when I opened this issue, I haven't seen it go as high as it used to. And I documented in my second comment that the allocated RAM is very slowly getting released again. That slow release has improved a little. Another thing I just noticed is that forcing the leak by rapidly making trivial edits and undoing them again and saving in between (#5733 (comment)) does not work quite as well now. I can get a couple hundred MB out of that, but it does not grow indefinitely anymore like it used to. Will need to do more testing to see just how much things have improved. But at least the LSP is not quite strangling my machine anymore while making light edits or just reading code. Edit: Actually I am having a hard time getting the allocated memory to go above 4GB when it was trivial to push it above 10gb before. Using version v2.0.320 of the "C#" extension and v0.4.2 of "C# Dev Kit". To the other commenters: Have you observed actual leaking (constant growth of allocated memory over time) or just a very high base utilization of memory? I'm seeing around 2.5gb right after the solution loads and the LSP is done with the initial scan. Then it goes to around 3GB and now stays there with some bursts above while I'm working on the project. |
@MihaPro-CarX Just to confirm there: Are you experiencing a memory leak or are you seeing that kind of allocation as a baseline that does not meaningfully and permanently increase as you work on the code? As per my last comment I have been unable to replicate a memory leak. I am not saying that having that kind of memory utilization is good. But distinguishing between high baseline memory and a leak is important and I'd be curious to figure out a reliable way of replicating that again. |
For anyone hitting memory, issues, if you can please send us a dump of the process. This can be collected with dotnet-dump - https://learn.microsoft.com/en-us/dotnet/core/diagnostics/dotnet-dump The process you'll be looking for on Windows / Linux is 'Microsoft.CodeAnalysis.LanguageServer.exe' (on mac it will be a dotnet.exe process launched against the Microsoft.CodeAnalysis.LanguageServer.dll). If you don't feel comfortable sharing publicly, my microsoft email is listed in my github profile. Some notes
|
I can't say it's a memory leak. We have a very large project, the solution contains 264 csproj. When you open a solution, memory consumption reaches a certain high level and remains there. My opinion is that this is a very large memory consumption by the analyzer, which begins to block work on the workstation. |
I probably have an idea of what the problem's cause might be. I have a program that runs C# scripts, or in other words, CSX files. I faced the same issue of excessive memory usage. The solution I found was elementary. When I executed the code, I used: // This is how I had it // This is how I use it now This solved the problem for me because it seems that RunAsync loads all debugging symbols every time it's called, and therefore, it consumes a lot of memory. On the other hand, when you create a delegate, they are loaded only once. |
Hi @dibarbet ! We have a medium size workspace with .Net code (approx. 30-40 csproj files). Running VS Code on Windows 11 and Microsoft.CodeAnalysis.LanguageServer is taking 9GB+! VS Code is extremely sluggish and i often have to re-build multiple times for intellisense to work, debugging unit tests works some times and doesnt other times. I have taken a memory dump of the Microsoft.CodeAnalysis.LanguageServer PID. How can I securely send it to you? |
@jrmegatron If that doesn't work you can create a fake VS feedback ticket if you have VS installed via Help-> Send Feedback -> Report a problem and then just attach the vscode dump to that ticket and send me the link to it We're still working out a better system to share large dumps 😆 |
@dibarbet I sent you an email directly with a link to download the dump file. Please confirm. Thanks. |
Got it downloaded - thanks! |
I experience high memory and CPU usage with Unity project (replaced old Unity extension with Microsoft's one). I can't say the project is exceptionally large (I even unchecked generating projects for packages), but after opening language server keeps working set at 6.1 Gb. (C# extension v2.1.2). My colleague said Rider fits into 4.4 Gb for the same project, but this includes whole app and all packages, not just language server. asp.net or dotnet-runtime took much less resources (although they may be opened differently since I couldn't do restore and just used loading on demand with the previous version of extension). |
Also noting that it goes up with each action (opening file, opening side bar...), but mem is not freed on closing the files. Working on a Unity project as well. |
Same here, 33 CSProj and it's taking over 17GB of RAM, 4GB on start |
It looks like having the options "Dotnet › Background Analysis: Analyzer Diagnostics Scope" and "Dotnet › Background Analysis: Compiler Diagnostics Scope" set to With Test procedure:
Tested solution size:
This might help some people with excessive memory utilization on big solutions. I have not tested the impact of the respective setting on the observed memory leak. Only idle memory directly after reaching steady state. Tested with the extension version v2.22.5. |
I was having problems with memory usage on the language server, but after reading this issue I was able to solve the problem for the last time.
Hope this helps some of you. |
Would be good to test repro after release of dotnet/roslyn#73201 |
In Total memory utilization when idle (and after reaching steady state w/ regards to solution analysis) also is lower. Before it was ~3gb, now it is ~2.1gb. I'll have to do more thorough testing, but I think this might be a fix as for the memory leaking. Unworkably high baseline memory use should probably be continue to be tracked in a separate issue. |
Repro here. Version latest pre release as of 2024-05-01
Result here, monotone increase in memory usage |
I can partially confirm that reproduction. It generally works, but I can not increase the memory footporint of the language server process beyond 1374mb with that method. And if I then do other stuff on the file that increases memory (such as removing some lines, adding the lines back, formatting the file, etc.) it then goes back down sometimes. Not sure if this is a leak per se or just some caches not being evicted and the memory space for those caches being rather big. |
@CyrusNajmabadi this discussion might pique your interest. |
For our project we easily see 10GB+ of memory usage right away, and sometimes rising to 20GB+ |
And here I was hoping I'd scroll down to a solution, only to be met with complaints as recent as today. At least I know that my solution running me at a baseline 2.4gb RAM and expanding to infinity is common. I find that, as inconvenient as it is, changing the scope to open files or reducing the max files for diagnostics tool in the settings as per the OP's suggestion is the only way to not choke my workstation. Since it's ongoing I'll try to investigate further, maybe there is something we can do on our end. |
Hi there, I spend 3 days for this issues, probabyly i tried all advice for this issue but no result. Is there any planed solution for c# dev kit, i dont wanna swicth to Rider. |
The only solution is Visual Studio. |
Actually my memory issue seems solved but define symbols are not working correctly, it seems all define symbols are disabled. |
Update on the reproductions: #5733 (comment) - those still work as I described, but the overall memory use is down. 900mb instead of 1.3gb. I thought I found a new way to make the language server leak properly, but it "only" goes to 3.1gb before it becomes stable:
This is also really heavy on the CPU. I had all my cores at 80% load during that. @MihaPro-CarX I think your symptoms deserve a separate issue. I have never seen elevated memeory on the ServiceHost.exe. Only the language server ( |
For me the Language Server tends to just eat all of my avaiable memory before crashing because it cant take any more. Im talking about a whopping 55 Gigabytes here. |
With the preview release 2.41.26 (https://github.com/dotnet/vscode-csharp/releases/tag/v2.41.26) I can no longer provoke any apparent "leak" when disabling the newly added Important to keep in mind that disabling server GC may hurt performance of the language server. I think that what I observed past my initial report with the rapid heap growth to 13 gigabytes was just the server garbage collector doing what it was designed to do. Unbearable baseline heap use as reported many many times in this issue notwithstanding, but that's a different category of bug. |
Yup - server GC is generally less aggressive at collecting back memory, so you can often see memory usage grow as long as you have available memory. We're also suspicious that there may be an issue where serverGC isn't appropriately releasing memory even under higher pressure. As for the relatively high baseline memory usage, we are always working on reducing memory usage (some of the changes can be seen in the changelog). However I wouldn't expect huge drops here, until we add features such as #6008 (to avoid needing to represent the entire solution at once in memory) |
I don't know if it's a solution or not, but i discovered i can work fine with unity by adding "dotnet.preferCSharpExtension": true to workspace settings.json, now my memory went from +10gb to 2-3gb and all define symbols are working fine too. |
Environment data
dotnet --info
output:VS Code version:
1.78.2
C# Extension version:
v2.0.206
OmniSharp log
Not applicable.
Steps to reproduce
Expected behavior
The LSP just works.
Actual behavior
Right out of the gate, the process "Microsoft.CodeAnalysis.LanguageServer" is utilizing about 1 to 1.5 GB of ram after the initial scan of the solution is complete. After navigating through the solution a bit, as one would for a bugfix or a small feature, the memory utilization jumps to 3-4 GB.
From there, memory utilization slowly creeps up as one continues to work on the solution. My "record" so far is 9.8 GB of utilized ram. I do have a lot of RAM, and I have it so I can use it. But this creeping up in utilization is a bit concerning and suggests to me that that there is a leak.
For context, the solution consists of
7471245 .cs files and8101344 cshtml files.Edit: As per my comment here #5733 (comment) I can no longer say that the LSP leaks per say. But many people still report elevated memory utilization. For me personally the issue is resolved.
Edit2: See #5733 (comment) for current reproduction.
If you experience high baseline memory
Try setting "Dotnet › Background Analysis: Analyzer Diagnostics Scope" and "Dotnet › Background Analysis: Compiler Diagnostics Scope" to
openFiles
.You can also try setting "Max Project File Count For Diagnostic Analysis" to a lower non-zero value. The default is
1000
- I have set it to250
.See also this comment for further context, if you suspect you may have a leak: #5733 (comment)
The text was updated successfully, but these errors were encountered: