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

Microsoft.CodeAnalysis.LanguageServer is taking 10gb of ram #1201

Closed
hrodrick opened this issue Jun 14, 2024 · 11 comments
Closed

Microsoft.CodeAnalysis.LanguageServer is taking 10gb of ram #1201

hrodrick opened this issue Jun 14, 2024 · 11 comments
Assignees
Labels
area-roslyn area-unity Unity support bug Something isn't working needs-more-info Needing more information, waiting on OP
Milestone

Comments

@hrodrick
Copy link

Type: Bug

I am working on a unity project. Everything was fine. But suddenly the process "Microsoft.CodeAnalysis.LanguageServer" is taking almost all the ram in my computer. Right now 9764.7 MB are being consumed by it. Becoming almost unusable
I see this information in Windows's Task Manager.

As a note, I am not debugging nor doing anything special. This happens right when I open Visual Studio Code. And in the Output I only see a lot of messages of different projecs loaded by C# Dev Kit. It was always like that but it never consumed that amount of memory before.

Extension version: 1.7.25
VS Code version: Code 1.90.1 (611f9bfce64f25108829dd295f54a6894e87339d, 2024-06-11T21:01:24.262Z)
OS version: Windows_NT x64 10.0.22631
Modes:

System Info
Item Value
CPUs AMD Ryzen 9 6900HX with Radeon Graphics (16 x 3294)
GPU Status 2d_canvas: enabled
canvas_oop_rasterization: enabled_on
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_graphite: disabled_off
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: enabled
Load (avg) undefined
Memory (System) 31.26GB (5.16GB free)
Process Argv C:\Users\rodri\Documents\projects\games\MMTD\Minimalist Multiplayer Tower Defense -g C:\Users\rodri\Documents\projects\games\MMTD\Minimalist Multiplayer Tower Defense\Assets\_project\Modules\UI\UGUI\SkillTree\Manager\SkillTreeManager.cs:1:0 --crash-reporter-id 6ad66de9-4507-4355-865a-fa2299f82af1
Screen Reader no
VM 0%
A/B Experiments
vsliv368cf:30146710
vspor879:30202332
vspor708:30202333
vspor363:30204092
vscod805:30301674
binariesv615:30325510
vsaa593cf:30376535
py29gd2263:31024239
c4g48928:30535728
azure-dev_surveyone:30548225
962ge761:30959799
pythongtdpath:30769146
welcomedialogc:30910334
pythonidxpt:30866567
pythonnoceb:30805159
asynctok:30898717
pythontestfixt:30902429
pythonregdiag2:30936856
pythonmypyd1:30879173
h48ei257:31000450
pythontbext0:30879054
accentitlementsc:30995553
dsvsc016:30899300
dsvsc017:30899301
dsvsc018:30899302
cppperfnew:31000557
dsvsc020:30976470
pythonait:31006305
jchc7451:31067544
chatpanelt:31048053
dsvsc021:30996838
da93g388:31013173
pythoncenvpt:31062603
a69g1124:31058053
dvdeprecation:31068756
pythonprt:31056678
dwnewjupytercf:31046870
2f103344:31071589

@webreidi webreidi added bug Something isn't working area-roslyn area-unity Unity support labels Jun 14, 2024
@jbevain
Copy link
Member

jbevain commented Jun 14, 2024

Hi @hrodrick,

That seems a bit excessive indeed.

Which version of Unity are you using?
How big is your Unity project in terms of C#? How many C# files/csprojs?

Screenshot 2024-06-14 at 10 10 41 AM

Are you generating project files for all your packages? Does this happen if you only generate project files for your in game code, and not for Unity packages?

Thanks!

@hrodrick
Copy link
Author

hrodrick commented Jun 14, 2024

Interesting, I had literally everything checked on.
At a first glance it looks like "Registry Packages" was the main cause. When on, it used 5gb of ram. And "Built-in packages" consumed another 1.3gb. So I disabled everything except embedded packages and local packages. The consumption was around 3.0gb.
Is is correct for those packages to consume that much ram?

Now, I was playing a bit more and it seems to be a memory leak somewhere. Look at this video (code at left, ram at right):

VSCode.-.bug.issue.mp4

I started to write and remove (with ctrl+z) that "GameEvents" line over and over. And the ram usage didn't stop to increase.
Whenever I add that line, the "using myProject.myGame" namespace is added to the file, and by removing it with ctrl+z the "using" statement gets removed. But the ram usage doesn't decrease.

Sounds silly but I believe it is actually an issue, because it increased 1.7gb of ram usage by just doing that. (from 3 to 4.7, I realize to record late). And it doesnt go down until I restart VSCode

@hrodrick
Copy link
Author

hrodrick commented Jun 14, 2024

Sorry I forgot to answer the other questions.
My Unity version is 2022.3.21f1 LTS
I think the project is small. Considering all the files within the .Assets folder (ie. mine and 3rd party). there is a total of 1856 C# files

@jbevain
Copy link
Member

jbevain commented Jun 14, 2024

Unity's model of having all packages as source means that if you check those, Unity will generate a csproj for each package (and asmdef in those packages). So you end up potentially with 50+ projects, that Roslyn will need to analyze so that you can do code navigation, find references and refactorings across them.

I'll share your video with the C# extension folks.

By any chance, would it be possible to share your project privately so that we could investigate exactly what you're looking at?

If not, could you share the list of Unity packages you're using?

@hrodrick
Copy link
Author

Hi! Sadly I can not share the project. But here is the list of unity packages:

  • 2D Features:
    • 2D Animation 9.1.0
    • 2D Pixel Perfect 5.0.3
    • 2D Common 8.0.2
    • 2D PSD Importer 8.0.4
    • 2D Sprite 1.0.0
    • 2D SpriteShape 9.0.2
    • 2D Tilemap Editor 1.0.0
    • 2D Tilemap Extras 3.1.2
    • 2D Aseprite Importer 1.1.1
  • Addressables 1.21.19
  • AI Navigation 1.1.15
  • Burst 1.8.12
  • Cinemachine 2.9.7
  • Cloud Diagnostics 1.0.7
  • Collections 1.2.4
  • Core RP Library 14.0.10
  • Custom NUnit 1.0.6
  • Editor Coroutines 1.0.0
  • Input System 1.7.0
  • Mathematics 1.2.6
  • Multiplayer Tools 1.1.0
  • Netcode for GameObjects 1.8.1
  • Newtonsoft Json 3.2.1
  • ProBuilder 5.2.2
  • Scriptable Build Pipeline 1.21.21
  • Searcher 4.9.2
  • Services Core 1.12.2
  • Settings Manager 2.0.1
  • Shader Graph 14.0.10
  • Splines 2.5.2
  • Test Framework 1.1.33
  • TextMeshPro 3.0.6
  • Timeline 1.7.6
  • Unity Profiling Core API 1.0.2
  • Unity Transport 1.4.1
  • Unity UI 1.0.0
  • Universal RP 14.0.10
  • Universal RP Config 14.0.9
  • Version Control 2.2.0
  • Visual Scripting 1.9.1
  • Visual Studio Editor 2.0.22

@jbevain
Copy link
Member

jbevain commented Jun 17, 2024

@hrodrick thanks! I can repro the memory just growing. I'll pass that along to the C# team.

@arunchndr arunchndr added this to the Aug2024 milestone Jun 25, 2024
@jbevain jbevain added area-unity Unity support and removed area-unity Unity support labels Jun 27, 2024
@MihaPro-CarX
Copy link

I have a large Unity project with 301 projects in Solution.
There is a very large memory consumption by the process: Microsoft.VisualStudio.Code.ServiceHost
Is this issue related to Microsoft.CodeAnalysis.LanguageServer?
The entire memory of the 32Gb working machine goes to VSCode. With the latest update
C# v2.39.28 (pre-release)
C# Dev Kit v1.9.8 (pre-release)
Memory consumption increased even more and it became impossible to work with Unity.

изображение

@sharwell
Copy link
Member

We would need a heap dump of the process(es) consuming excess memory in order to start investigating this issue. I'm not sure how a VS Code user would be expected to complete this, since the "Report Issue" feature of VS Code posts issues publicly.

@sharwell sharwell added the needs-more-info Needing more information, waiting on OP label Sep 11, 2024
@sharwell sharwell modified the milestones: Aug2024, Backlog Sep 11, 2024
@ZezhongWang
Copy link

Had the same issue. It doesn't help if I switch to the pre-release version for c# Dev Kit v1.11.x.

@MihaPro-CarX
Copy link

My problem is related to ServiceHost and fixed in C# Dev Kit 1.9.2 and later.
#1295 (comment)

@arunchndr
Copy link
Member

Closing based on recent comments. Please reopen if this is still an issue with a dump and send it to arkalyan@microsoft.com. I will route it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-roslyn area-unity Unity support bug Something isn't working needs-more-info Needing more information, waiting on OP
Projects
None yet
Development

No branches or pull requests

7 participants