-
Notifications
You must be signed in to change notification settings - Fork 687
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
Consistent high cpu load in latest preview (v.2.48.31) #7582
Comments
@tverboon which process is causing the high CPU usage? You may need to post the process command line string to differentiate (on Mac the C# extension processes are usually all Once you've identified the process, could you collect a trace of it via dotnet-trace? You can email it to me (dabarbet@microsoft.com) if you don't want to upload here. Thanks! |
It's actually ReleaseRelease.mp4PreviewPreview.mp4TraceLast part of loading trace of preview. I don't think this process is a problem at this point. dotnet_20240925_074526.nettrace.zip SummaryConsistent high CPU load is not the issue. |
@tverboon thanks, I will take a look at the trace to see if anything stands out. The
|
@dibarbet thanks. I will investigate the extensions tomorrow. What do you think about the multiple attempts to load the razor files, because part of the directory path is duplicate causing files not being found? Could that be the issue why loading the projects takes much longer? |
To confirm - loading projects w/ C# extension prerelease takes 3 minutes, but 42 seconds in release? And it is the same version of C# Dev Kit both times? I wouldn't think that the Razor file loading attempts would slow down project loading, but tagging @ryzngard in case he's seen anything there. I'll need to dig into the trace to figure out more. |
Confirmed. Everything else is the same. I only switch between release and prerelease of the C# extension. Then I quit and start VSCode to start fresh. |
File paths being wrong could be a bug, but I wouldn't expect it to fix over time. For the razor logs it would be a bit more helpful to enable trace logging with this config "razor.server.trace": "Trace" if you don't feel comfortable posting the logs on GH feel free to e-mail them to my MS address directly but please zip :) |
@dibarbet Previewdotnet_20240926_081730.nettrace.zip Release |
@ryzngard From the logging it seems that the right paths are loaded also. See attached. |
Thanks! Will take a look at these today. |
Could you find anything useful in the trace and log files? |
@tverboon I did, apologies for not following up that day - I was going to ask for another trace but fell off my radar. Interestingly there wasn't much actually happening inside the language server in either trace. It looks almost the entire difference is the server just waiting (though no indication on what it is waiting for). Likely either lock contention, or waiting on the other processes (Razor/ Devkit). Request for the following
|
@dibarbet it looks like we don't have the PID on startup, but there is a message when the named pipe connects:
|
@dibarbet No problem David. I know you are working really hard to improve our developer experience. It's really appreciated! C#dotnet_20241022_133645.nettrace.zip Razordotnet_20241022_140734.nettrace.zip @ryzngard I hope I got the right process. I couldn't find the log entry you mentioned. Also after a few seconds the start of the log file is removed. The file is growing really fast, maybe some buffer issue? But regardless I found the process with |
That seems right Still digging into these, but the Razor trace also shows the majority of the time waiting. I suspect we may both be waiting on C# Dev Kit to send us the project information, as in the latter half of both Unfortunately the trace doesn't seem to have recorded any of the contention events - looks like there's a difference in behavior in
I've also been attempting to reproduce this myself on my Mac, but unfortunately I'm not seeing major differences between different versions of the extension (loading a ~200 project sln), and no exceedingly high continued cpu usage after projects load. I assume you're still seeing both issues on the latest prerelease (2.52)? I think the next step is to dig into the devkit processes, but I'll need to figure out the best way to capture traces of them. Additionally there is on-going work to improve startup time which we hope to have available in the next couple of releases which may help here. |
The trace was done with the latest prerelease. Just as before, between 2.45 and 2.52 it just takes a couple of minutes longer to get a fully functioning up to speed environment with codelens etc. This is after project loading completed. I might have found a clue in the Razor logs that Razor ProjectService is updating Projects. This takes about 3 minutes, after that CPU usage of csharp process comes down and everything is working fast. This project updating is after the project loading spinner is gone.
Trace of project loading.
I also noticed Dustin Campbell is doing a lot of work around the Razor project system, maybe it's wise to wait and not chase a moving target. This is not a show stopper for me. It just takes a little longer to load and CPU usage eventually comes down. As long as I don't have to restart VS Code during the day, it's not a big problem. |
Finally was able to get back to this. Thanks for the updated trace. As expected there is some contention, but only about 0.4% of the cpu time. I was also able to reproduce this in a large Razor project (on Windows as well) using MudBlazor. Essentially what looks to be happening is that Razor is triggering LSP didOpen/didClose for every virtual C# file and Razor file. This can block other LSP requests from running (didOpen/didClose are special here). The behavior appears to be similar in both 2.45 and later versions - however there are a couple differences-
Passing this on to the Razor folks - @ryzngard is there any way we can avoid sending LSP didOpen/didChanges for (what looks to be) every Razor and virtual C# file? These LSP requests completely block other LSP requests from running. Is this going to improve once we switch to the source generator for C# generation? |
@dibarbet Thanks for following up. Did you also notice the didOpen and didClose events with wrong paths, like I mentioned in my opening comment? didOpen for virtualcsharp-razor:///Users/tverboon/Desktop/Code/Midmid/src/Midmid.Shop.Common.Web /Users/tverboon/Desktop/Code/Midmid/src/Midmid.Shop.Common.Web /Views/Shared/DisplayTemplates/EmailAddress.cshtml__virtual.cs The correct paths are also loaded, but these wrong paths are causing extra opening and closing events. See also above: #7582 (comment) |
Thanks for the traces and reporting @tverboon ! |
Thanks @ryzngard! On my machine our project load time is also almost cut in half. Nice work! |
Type: Bug
Issue Description
While loading projects CPU usage is consistently around and above 100% CPU. That's 1 core on Mac.
Steps to Reproduce
Start VSCode and load our solution with latest C# plugin.
Expected Behavior
After loading projects cpu usage should come down.
Actual Behavior
Keeps opening and closing files causing high cpu usage.
Logs
Latest preview v2.48.31
Latest release v2.45.25
I hoped to only paste logs that are relevant, but I can upload everything when this is not enough.
The most obvious difference is, the parent directory file path is duplicated in the latest preview release.
/Users/tverboon/Desktop/Code/Midmid/src/Midmid.Shop.Common.Web/Users/tverboon/Desktop/Code/Midmid/src/Midmid.Shop.Common.Web/Views/Shared/DisplayTemplates/EmailAddress.cshtml__virtual.cs
It also seems to be only happening with razor files.
Razor logs:
The last line is warning that the file didn't exist, I am sure it doesn't because that path also has the duplicate parent folder.
Environment information
VSCode version: 1.93.1
C# Extension: 2.48.31
Using OmniSharp: false
Dotnet Information
.NET SDK: Version: 8.0.104 Commit: 034f91fcc0 Workload version: 8.0.100-manifests.9f663350Runtime Environment:
OS Name: Mac OS X
OS Version: 14.6
OS Platform: Darwin
RID: osx-arm64
Base Path: /usr/local/share/dotnet/sdk/8.0.104/
.NET workloads installed:
Workload version: 8.0.100-manifests.9f663350
There are no installed workloads to display.
Host:
Version: 8.0.4
Architecture: arm64
Commit: 2d7eea2529
.NET SDKs installed:
6.0.300 [/usr/local/share/dotnet/sdk]
7.0.202 [/usr/local/share/dotnet/sdk]
8.0.104 [/usr/local/share/dotnet/sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 6.0.5 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.4 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 8.0.4 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 6.0.5 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.4 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.4 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Other architectures found:
None
Environment variables:
Not set
global.json file:
Not found
Learn more:
https://aka.ms/dotnet/info
Download .NET:
https://aka.ms/dotnet/download
Visual Studio Code Extensions
Extension version: 2.45.25
VS Code version: Code 1.93.1 (38c31bc77e0dd6ae88a4e9cc93428cc27a56ba40, 2024-09-11T17:20:05.685Z)
OS version: Darwin arm64 23.6.0
Modes:
System Info
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
webgl: enabled
webgl2: enabled
webgpu: enabled
webnn: disabled_off
A/B Experiments
The text was updated successfully, but these errors were encountered: