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

Latest vscode extension causes massive spike in CPU usage even when idle #2734

Open
u84six opened this issue Oct 11, 2022 · 27 comments
Open

Comments

@u84six
Copy link

u84six commented Oct 11, 2022

[provide a description of the issue]

Environment
  • Operating System: Windows 10
  • JDK version: 11.0.12
  • Visual Studio Code version: 1.72.1
  • Java extension version: latest as of (Oct 11/22)
Steps To Reproduce
  1. After the extension was updated, my fans on my laptop went into high gear.
  2. Opened performance monitor and noticed that java updater was pinning the CPU
  3. I then opened vscode and looked at all the extensions that I have enabled and latest updated.
  4. Noticed that Java Redhat extension has been recently updated.
  5. Disabled the extension and CPU went back to normal and fans stopped spinning.

There's really nothing else to say. The extension updated and caused massive CPU spikes when vscode is running. Disabling the extension fixed the problem.

@rgrunber
Copy link
Member

Are you able to share the sample project that was used when this happened ? Was it a Maven, Gradle, or un-managed project.

@u84six
Copy link
Author

u84six commented Oct 12, 2022 via email

@snjeza
Copy link
Contributor

snjeza commented Oct 12, 2022

@u84six Could you try to add

"java.jdt.ls.vmargs": "-DwatchParentProcess=false -XX:+UseParallelGC -XX:GCTimeRatio=4 -XX:AdaptiveSizePolicyWeight=90 -Dsun.zip.disableMemoryMapping=true -Xmx3G -Xms100m -Xlog:disable"

to your settings.json?

@snjeza
Copy link
Contributor

snjeza commented Oct 12, 2022

I can't reproduce the issue?
@u84six Could you show your Extension view?
ext

@u84six
Copy link
Author

u84six commented Oct 13, 2022 via email

@snjeza
Copy link
Contributor

snjeza commented Oct 13, 2022

I'm not sure how a screenshot of my extension view is going to help, but here it is:

I suppose VS Code hasn't finished updating Java LS.

I had no project.

In this case, VS Code doesn't start Java LS, but will try to update it.

@u84six
Copy link
Author

u84six commented Oct 13, 2022 via email

@snjeza
Copy link
Contributor

snjeza commented Oct 13, 2022

@u84six You can add

"update.enableWindowsBackgroundUpdates": false,

to your setting.json.
It will disable background updates.

@u84six
Copy link
Author

u84six commented Oct 14, 2022 via email

@u84six
Copy link
Author

u84six commented Oct 14, 2022 via email

@rgrunber
Copy link
Member

For the "OpenJDK Platform binary" processes in your task manager, is it possible to look at their properties/details or even the "command line" tab and tell us what arguments are being passed to this Java process ? It may give us a better idea of whether these are processes started by vscode-java or something else.

@u84six
Copy link
Author

u84six commented Oct 14, 2022 via email

@snjeza
Copy link
Contributor

snjeza commented Oct 14, 2022

How long is this going to last?

It depends on your Internet connection. It lasts less than 1 minute on my machine (4-5mb/sec).

@deepesh1511
Copy link

I have started facing similar issue very recently, will check if disabling the extension helps in my case.

@rainkings
Copy link

Hi, guys.
I have exactly the same issue!!!!!, which drives me mad.
But I am not using the java extension. Usually I just write latex with vscode and the OpenJDK begins to occupy my CPU to 100%. I still don't have clear clues on it. If you know how to solve it, please Email me ([email protected])! Thanks !!!!!

@rainkings
Copy link

Hi, guys. I have exactly the same issue!!!!!, which drives me mad. But I am not using the java extension. Usually I just write latex with vscode and the OpenJDK begins to occupy my CPU to 100%. I still don't have clear clues on it. If you know how to solve it, please Email me ([email protected])! Thanks !!!!!

I guess I find the reason. The extension Ltex, which help you do gammer/spell check that activate java.exe. By enabling it, java.exe is no longer awakened when writng latex. Apparently there is some bugs in Ltex. ....

@kanatti
Copy link

kanatti commented Feb 4, 2024

I am see this same issue, where redhat.java extension is taking up all the CPU (4 out 8 cores 100%).

Though this happens only when I open a specific file which is like a large Base class. On CMD + hovering on any variable within that file, vscode just shows loading....

Issue doesnt go away even if I close that file. I have to manually kill the extension process and it comes up back normal.

If you can let me know what else to check for diagnostics, I can do that and provide more info.

@snjeza
Copy link
Contributor

snjeza commented Feb 4, 2024

@kanatti Could you attach a project example?

@kanatti
Copy link

kanatti commented Feb 4, 2024

Sorry. I don't have any other examples than the actual project, which is private code.

I also noticed that if I disable lombok there is no issue ("java.jdt.ls.lombokSupport.enabled": false)

@kropptrevor
Copy link

Sorry. I don't have any other examples than the actual project, which is private code.

I also noticed that if I disable lombok there is no issue ("java.jdt.ls.lombokSupport.enabled": false)

This was helpful, and fixed it for me. I wanted to add, though, that when I re-enabled lombok support, the problem didn't come back. So, even though I cleaned many times, it seems maybe something wasn't getting cleaned up.
Needless to say, this is a different problem.

@rgrunber
Copy link
Member

There were some recent improvements to project import ( #3637 ) so it could have been that if it was very recent.

@kropptrevor
Copy link

There were some recent improvements to project import ( #3637 ) so it could have been that if it was very recent.

Just to be clear, this has been happening for months.
The VSCode process manager showed 0 CPU usage for everything under the extension host, but the extension host itself was sitting at 12 (1 core worth).
I noticed the problem actually came back, but then I fiddled with the configuration again and that fixed it again.
It's not clear that it's even caused by this extension, but I've only ever seen it with this extension enabled.

If you can provide some guidance on what other debug information we can collect, I can provide that next time it happens.

@rgrunber
Copy link
Member

rgrunber commented Jun 26, 2024

Would someone be able to check if the issue still occurs with the latest pre-release of vscode-java (v1.32.2024062508) ? Just last week, we fixed a serious issue relating to null analysis that would have caused this similar behaviour (CPU spike when idle), #3387 .

What's interesting, is this issue was originally reported in October 2022, and null analysis was first introduced at the end of September 2022.

@Gergall
Copy link

Gergall commented Dec 5, 2024

I hope that this fix helps someone:

I work with a large java project in VS Code and my CPU usage problems were because "java autobuild" was on so every time I made the slightest change it wanted to rebuild the entire project automatically.

To correct this issue, I went to File-Preferences-Settings and then searched for the setting called java autobuild and unchecked it.

Then I closed VS Code and used Task Manager to force quit whatever the task was that was using 99% of my CPU (JDK something). A reboot would also work I suppose.

After that, no more autobuilding and no more problems. Hope someone finds this useful.

@knguyen1
Copy link

knguyen1 commented Dec 18, 2024

@kanatti Could you attach a project example?

Try this project: https://github.com/apache/nifi.git

Attach this to your .devcontainer. You need the devcontainer extension -> create a .devcontainer directory -> place the below json into devcontainer.json -> F1 -> Dev Containers: Rebuild and Reopen in Dev Container. Start it -> java will auto build. Then exit vscode completely. The devcontainer remains and takes up CPU--god knows why.

{
    "image": "mcr.microsoft.com/devcontainers/python:3.11",
    "features": {
      "ghcr.io/devcontainers/features/java:1": {
        "version": "21"
      },
      "ghcr.io/devcontainers-extra/features/maven-sdkman:2": {
        "version": "latest"
      }
    },
    "customizations": {
      "vscode": {
        "extensions": [
          "vscjava.vscode-java-pack",
          "ms-python.python",
          "ms-python.vscode-pylance"
        ]
      }
    },
    "mounts": [
        "source=${localEnv:HOME}/.m2,target=/home/vscode/.m2,type=bind",
        "source=${localEnv:HOME}/.ssh,target=/home/vscode/.ssh,type=bind,readonly=true"
    ]
  }

Image

@snjeza
Copy link
Contributor

snjeza commented Dec 18, 2024

Try this project: https://github.com/apache/nifi.git
Attach this to your .devcontainer

Could you reproduce the issue out of Dev Container?
I tried to import the nifi project. Importing takes a while for the first time, but after that, it works pretty well.

Start it -> java will auto build

Did you wait for the project to be built?

@knguyen1
Copy link

Did you wait for the project to be built?

I left it running for the whole day. It never finished. Even after I run ./mvnw install -T3C to completion (it's their maven wrapper), the extension still runs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants