vscode-java icon indicating copy to clipboard operation
vscode-java copied to clipboard

Whole project recompiles with each keystroke

Open xster opened this issue 4 years ago • 104 comments
trafficstars

Sometime between version 0.64.1 and now, the build triggering behavior seems to have changed. Whereas changes within a file still produced a reasonably fast auto-complete, it seems like each keystroke now triggers a rebuild of the entire project including the edited file, other files in the project and all declared Java dependencies. This seems to generally make auto-complete unusable since one is likely typing around the time auto-complete is needed and if each keystroke triggers a 1 minute build, auto-complete is generally always loading.

Perhaps it's possible to restrict the rebuilding to the edited file, or cache all the symbols from the previous build until the next build is ready?

Environment
  • Operating System: macOS 10.15
  • JDK version: 11.0.4
  • Visual Studio Code version: 1.52.1
  • Java extension version: 0.64.1
Additional Informations

When I start typing, it triggers the below in the Java Build Status pane. Each build takes a few minutes.

8394ded0 Building [Done]
ba7e2d19 Validate documents [Done]
00cd587d Publish Diagnostics [Done]
c9fb754c Building [Done]
467b8d20 Building [Done]
a25e99a1 Validate documents [Done]
411b4544 Publish Diagnostics [Done]
c1bd89da Building [Done]
240f6be2 Building [Done]
a3536bca Building [Done]
6cea6ad2 Building [Done]

xster avatar Jan 14 '21 07:01 xster

Duplicated with https://github.com/redhat-developer/vscode-java/issues/996

The "Building" message you saw in the status panel is just a fake message, not representing a compilation operation.

testforstephen avatar Jan 14 '21 07:01 testforstephen

Java extension version: 0.64.1

Your Java extension version is a little old, could you update all Java extensions to the latest version and try again?

AFAIK, the side Java extensions such as Java test runner pushed a bunch of performance improvement against the auto completion performance in the past few months.

BTW, do you enable file auto save? the file save is probably triggering the auto build job.

testforstephen avatar Jan 14 '21 08:01 testforstephen

Thanks.

File auto save is off. I'm trying now on 0.73.0 with Java 11. Same symptom. I think the "building" messages are actually doing something, since each of them breaks down (while running) into a building 123/1000 files message.

xster avatar Jan 15 '21 05:01 xster

I can confirm this issue for me. Each keystroke causes the circular arrow to rotate and I get similar messages like shared above. I had disabled java autobuild and auto save was disabled by default for me

deekshithanand avatar Jan 18 '21 18:01 deekshithanand

The "Publish Diagnostics" takes the longest for me. I frequently see java processes (2 of them because of the hybrid mode) in the background hugging the CPU (200-300% spikes), notably after the change to a Java file is made. It slows down the intellisence, and one has to wait for good 10-30 seconds for the auto-completion hints to appear. I attempted the following:

  • setting user-level "telemetry.telemetryLevel": "crash" - didn't have any effect (would be nice if Java respected that, actually).
  • setting workspace-level "redhat.telemetry.enabled": null or false - seems like does not have any effect and only applies to the Kubernetes plugin.
  • reloading the vscode, clearing the Java workspace cache, etc - nothing worked.

If I can make a suggestion:

  • it would be nice if background compilation could be debounced somehow (i.e. start background build after a few seconds of accumulating changes and after there has been no changes for couple more seconds). This way we would not have "wasted" compilation cycles as user types.
  • do not block intellisense and auto-completion on background tasks. I'd rather have it slightly out of date but immediately available rather than waiting half of minute for it to come back with a better result. For things like refactoring I don't mind waiting though.

dbarvitsky avatar Aug 11 '22 15:08 dbarvitsky

Same here. Intellisense performance is terrible. Any update?

kkilictepe avatar Sep 03 '22 01:09 kkilictepe

Same issue, would love an update.

DrewCCannedy avatar Oct 24 '22 20:10 DrewCCannedy

@DrewCCannedy @kkilictepe @dbarvitsky @deekshithanand @xster Could you provide a project example reproducing the issue?

snjeza avatar Oct 24 '22 20:10 snjeza

@snjeza I cant share as I am working on a commercial project.Anything else (logs etc?) that I can provide but the project codes itself? My project is huge, with a lot of internal dependencies.

kkilictepe avatar Oct 25 '22 08:10 kkilictepe

I actually found out what could be the issue. I started with the same problem as described by @xster with a cyclic Building,Validate,Publish routine at each keystroke.

After I've searched for build in the full settings page, I found that the extension "Language Support for Java(TM) by Red Hat" (ID: redhat.java) has a setting named "Java > Autobuild: Enabled" ("java.autobuild.enabled") set at True by default. It triggers (as the name says) an automatic build after some event (code/text changes). After I disabled it the automatic fire of the build has stopped. It only keeps doing the "Validating" step at each keystroke and sometimes the "Publish" one.

Probably the Validating step is controlled by the intellisense to validate the code at each change. It could be made after a delay, but for me it's not impacting the performance a lot as the Build step.

Intellisense speeded up even in complex legacy projects and it seems the entire usability has improved. Actually I'm still trying to find out what are the downsides of haing disabled that autobuild.

Let me know if you know something about that feature.

d3milord avatar Oct 27 '22 13:10 d3milord

@d3milord If you set java.autobuild.enabled=true , Java LS will build your workspace only when you save a file. Could you show your settings.json?

snjeza avatar Oct 27 '22 14:10 snjeza

{
    "java.jdt.ls.vmargs": "-XX:+UseParallelGC -XX:GCTimeRatio=4 -XX:AdaptiveSizePolicyWeight=90 -Dsun.zip.disableMemoryMapping=true -Xmx1G -Xms100m -javaagent:\"c:\\Users\\davidepecorari\\.vscode\\extensions\\gabrielbb.vscode-lombok-1.0.1\\server\\lombok.jar\"",
    "files.exclude": {
        "**/.classpath": true,
        "**/.project": true,
        "**/.settings": true,
        "**/.factorypath": true
    },
    "redhat.telemetry.enabled": false,
    "editor.suggestSelection": "first",
    "vsintellicode.modify.editor.suggestSelection": "automaticallyOverrodeDefaultValue",
    "git.confirmSync": false,
    "git.enableSmartCommit": true,
    "java.configuration.runtimes": [
        {
          "name": "JavaSE-1.8",
          "path": "C:\\Program Files\\Java\\jdk1.8.0_202",
        },
        {
          "name": "JavaSE-11",
          "path": "C:\\Program Files\\Java\\jdk-11.0.13",
          "default": true
        }
    ],
    "java.referencesCodeLens.enabled": true,
    "java.debug.settings.showHex": true,
    "json.schemas": [],
    "workbench.startupEditor": "none",
    "workbench.colorCustomizations": {},
    "java.inlayHints.parameterNames.enabled": "none",
    "workbench.editor.enablePreviewFromQuickOpen": true,
    "workbench.editor.enablePreview": false,
    "java.debug.settings.enableRunDebugCodeLens": false,
    "java.help.showReleaseNotes": false,
    "java.autobuild.enabled": false,
    "maven.dependency.enableConflictDiagnostics": false,
    "javascript.suggestionActions.enabled": false,
    "typescript.suggestionActions.enabled": false
}

d3milord avatar Oct 28 '22 08:10 d3milord

@d3milord could you remove the gabrielbb.vscode-lombok extension and update java.jdt.ls.vmargs to

 "java.jdt.ls.vmargs": "-XX:+UseParallelGC -XX:GCTimeRatio=4 -XX:AdaptiveSizePolicyWeight=90 -Dsun.zip.disableMemoryMapping=true -Xmx4G -Xms100m ",
   

See Lombok Support

snjeza avatar Oct 28 '22 14:10 snjeza

I can confirm this is happening to me on a large enterprise Java Project with hundreds of classes (sometimes large ones too, 6000+ lines of code). It's a Spring Boot Gradle Project, and I got the message that the language server got out of memory.

When I do get an Intellisense suggestion it comes with a 20 seconds delay (when lucky), often it shows no popup at all, making it hardly usable.

The curious thing here is how fast is Language Server for Java by Netbeans instead, while it doesn't have the features I need the code suggestion are almost instantly provided.

I did my tests on a brand new vscode installation with vscode-java only enabled as extension.

francescodedomenico avatar Jan 27 '23 07:01 francescodedomenico

I have the same issue here. I am working on a large project with hundreds of classes. Right now anytime I make a keystroke, "Publish Diagnostics" tasks take me 5s to complete and the intellisense popup triggered after that. That makes me wait for at least 5s to get my intellisense shown up. It is a disaster when I doing my implementation. I do not want to swtich to IntelliJ but if the speed is that slow I have no choice

https://user-images.githubusercontent.com/4750762/215580386-a5a0bea0-eafa-4650-a124-a59bb66ff900.mp4

iamfreeman avatar Jan 30 '23 19:01 iamfreeman

@iamfreeman Could you attach your server log? - Enable logging

snjeza avatar Jan 30 '23 20:01 snjeza

@snjeza, not a problem. I have attached the server log at the time I hit "v" key as shown in my previous video.

!ENTRY org.eclipse.jdt.ls.core 1 0 2023-01-30 12:27:47.273 !MESSAGE >> document/codeAction

!ENTRY org.eclipse.jdt.ls.core 1 0 2023-01-30 12:27:47.393 !MESSAGE >> textDocument/inlayHint

!ENTRY org.eclipse.jdt.ls.core 1 0 2023-01-30 12:27:47.467 !MESSAGE >> document/codeAction

!ENTRY org.eclipse.jdt.ls.core 1 0 2023-01-30 12:27:47.513 !MESSAGE >> workspace/executeCommand vscode.java.resolveMainMethod

!ENTRY org.eclipse.jdt.ls.core 1 0 2023-01-30 12:27:48.232 !MESSAGE >> document/foldingRange

!ENTRY org.eclipse.jdt.ls.core 1 0 2023-01-30 12:27:48.501 !MESSAGE >> document/didChange

!ENTRY org.eclipse.jdt.ls.core 1 0 2023-01-30 12:27:48.509 !MESSAGE >> document/completion

!ENTRY org.eclipse.jdt.ls.core 1 0 2023-01-30 12:27:48.517 !MESSAGE Reconciled 1. Took 4 ms

!ENTRY org.eclipse.jdt.ls.core 1 0 2023-01-30 12:27:53.825 !MESSAGE Completion request completed

!ENTRY org.eclipse.jdt.ls.core 1 0 2023-01-30 12:27:53.838 !MESSAGE >> document/codeAction

!ENTRY org.eclipse.jdt.ls.core 1 0 2023-01-30 12:27:53.839 !MESSAGE >> workspace/executeCommand vscode.java.resolveMainMethod

!ENTRY org.eclipse.jdt.ls.core 1 0 2023-01-30 12:27:53.839 !MESSAGE >> document/documentSymbol

!ENTRY org.eclipse.jdt.ls.core 1 0 2023-01-30 12:27:53.839 !MESSAGE >> document/foldingRange

!ENTRY org.eclipse.jdt.ls.core 1 0 2023-01-30 12:27:53.840 !MESSAGE >> textDocument/semanticTokens/full

!ENTRY org.eclipse.jdt.ls.core 1 0 2023-01-30 12:27:53.840 !MESSAGE >> textDocument/inlayHint

!ENTRY org.eclipse.jdt.ls.core 1 0 2023-01-30 12:27:53.869 !MESSAGE >> workspace/executeCommand vscode.java.resolveMainMethod

!ENTRY org.eclipse.jdt.ls.core 1 0 2023-01-30 12:27:53.884 !MESSAGE >> document/resolveCompletionItem

!ENTRY org.eclipse.jdt.ls.core 1 0 2023-01-30 12:27:54.251 !MESSAGE begin problem for /TblVendorService.java

!ENTRY org.eclipse.jdt.ls.core 1 0 2023-01-30 12:27:54.251 !MESSAGE 3 problems reported for /TblVendorService.java

!ENTRY org.eclipse.jdt.ls.core 1 0 2023-01-30 12:27:54.252 !MESSAGE Validated 1. Took 5324 ms

!ENTRY org.eclipse.jdt.ls.core 1 0 2023-01-30 12:27:54.513 !MESSAGE >> document/codeAction

iamfreeman avatar Jan 30 '23 20:01 iamfreeman

I have attached the server log at the time I hit "v" key as shown in my previous video.

Could you set

"java.trace.server": "verbose",

and repeat the log?

snjeza avatar Jan 30 '23 20:01 snjeza

This is the setting for my user workspace, I use this setting to generate my previous log:

{
    "java.codeGeneration.generateComments": true,
    "security.workspace.trust.untrustedFiles": "open",
    "java.eclipse.downloadSources": true,
    "java.import.exclusions": [

        "**/node_modules/**",
        "**/.metadata/**",
        "**/archetype-resources/**",
        "**/META-INF/maven/**"
    ],
    "java.maxConcurrentBuilds": 2,
    "java.showBuildStatusOnStart.enabled": "notification",
    "java.trace.server": "verbose",
    "java.typeHierarchy.lazyLoad": true,
    "javascript.updateImportsOnFileMove.enabled": "always"
}

This is the setting for my project, this time, I add the : "java.trace.server": "verbose", to my project setting as well:

{
    "java.configuration.updateBuildConfiguration": "automatic",
    "sqltools.connections": [
        {
            "mysqlOptions": {
                "authProtocol": "default"
            },
            "previewLimit": 50,
            "server": "localhost",
            "port": 3306,
            "driver": "MySQL",
            "name": "root-local",
            "database": "xxxxx",
            "username": "xxxx",
            "password": "xxxx"
        }
    ],
    "java.trace.server": "verbose",
    "java.jdt.ls.vmargs": "-XX:+UseParallelGC -XX:GCTimeRatio=4 -XX:AdaptiveSizePolicyWeight=90 -Dsun.zip.disableMemoryMapping=true -Xmx4G -Xms1G -Xlog:disable"
}

I got the pretty much the same result from the server log:

!ENTRY org.eclipse.jdt.ls.core 1 0 2023-01-30 13:21:02.306 !MESSAGE >> document/codeAction

!ENTRY org.eclipse.jdt.ls.core 1 0 2023-01-30 13:21:02.570 !MESSAGE >> workspace/executeCommand vscode.java.resolveMainMethod

!ENTRY org.eclipse.jdt.ls.core 1 0 2023-01-30 13:21:02.898 !MESSAGE >> textDocument/inlayHint

!ENTRY org.eclipse.jdt.ls.core 1 0 2023-01-30 13:21:02.983 !MESSAGE >> document/didChange

!ENTRY org.eclipse.jdt.ls.core 1 0 2023-01-30 13:21:02.988 !MESSAGE >> document/completion

!ENTRY org.eclipse.jdt.ls.core 1 0 2023-01-30 13:21:03.003 !MESSAGE Reconciled 1. Took 7 ms

!ENTRY org.eclipse.jdt.ls.core 1 0 2023-01-30 13:21:08.044 !MESSAGE Completion request completed

!ENTRY org.eclipse.jdt.ls.core 1 0 2023-01-30 13:21:08.052 !MESSAGE >> document/codeAction

!ENTRY org.eclipse.jdt.ls.core 1 0 2023-01-30 13:21:08.053 !MESSAGE >> workspace/executeCommand vscode.java.resolveMainMethod

!ENTRY org.eclipse.jdt.ls.core 1 0 2023-01-30 13:21:08.054 !MESSAGE >> document/documentSymbol

!ENTRY org.eclipse.jdt.ls.core 1 0 2023-01-30 13:21:08.054 !MESSAGE >> textDocument/inlayHint

!ENTRY org.eclipse.jdt.ls.core 1 0 2023-01-30 13:21:08.054 !MESSAGE >> document/foldingRange

!ENTRY org.eclipse.jdt.ls.core 1 0 2023-01-30 13:21:08.054 !MESSAGE >> textDocument/semanticTokens/full

!ENTRY org.eclipse.jdt.ls.core 1 0 2023-01-30 13:21:08.092 !MESSAGE >> document/resolveCompletionItem

!ENTRY org.eclipse.jdt.ls.core 1 0 2023-01-30 13:21:08.309 !MESSAGE >> workspace/executeCommand vscode.java.resolveMainMethod

!ENTRY org.eclipse.jdt.ls.core 1 0 2023-01-30 13:21:08.619 !MESSAGE begin problem for /TblVendorService.java

!ENTRY org.eclipse.jdt.ls.core 1 0 2023-01-30 13:21:08.620 !MESSAGE 3 problems reported for /TblVendorService.java

!ENTRY org.eclipse.jdt.ls.core 1 0 2023-01-30 13:21:08.620 !MESSAGE Validated 1. Took 5216 ms

!ENTRY org.eclipse.jdt.ls.core 1 0 2023-01-30 13:21:08.886 !MESSAGE >> document/codeAction

@snjeza , Did I miss something?

iamfreeman avatar Jan 30 '23 21:01 iamfreeman

Did I miss something?

@xster Could you check your .vscode/settings.json?

snjeza avatar Jan 30 '23 21:01 snjeza

@xster Could you also try to set

"java.completion.maxResults": 50,

snjeza avatar Jan 30 '23 21:01 snjeza

Hi @snjeza , same result, no difference. I also tried on my my colleague's workstation, still, the same result. I relaunch VSCode and tried again. Same result

iamfreeman avatar Jan 30 '23 22:01 iamfreeman

I got the pretty much the same result from the server log:

Could you try to clean the workspace directory:

  • Open the command palette (F1)
  • select Java: Clean the Java Language Server Workspace
  • select Restart and delete from the confirmation prompt

snjeza avatar Jan 30 '23 22:01 snjeza

Currently this is happening to me on a @Service Spring java class with 6700+ lines of code and lots of imports and @Autowired.

On smaller classes the build step is fast enough to provide intellicode suggestions.

In this particular one the "Publish Diagnostics" step is very slow and usually results in several loops after each "dot" pressed after a local variable eg: iAmAVariable. (expected intellisense popup here)

af9f56d5 Validate documents [Done] fc5b1b21 Publish Diagnostics [Done] 13e3c4a4 Validate documents [Done] af8bbb62 Publish Diagnostics [Done] a5b94203 Validate documents [Done] 08467232 Publish Diagnostics [Done] 4c3aed8f Validate documents [Done] 48130557 Validate documents [Done] c810c682 Validate documents [Done] 5f310a3d Validate documents [Done] 3609b0b3 Publish Diagnostics [Done] b8b61fed Validate documents [Done] 6843baf8 Publish Diagnostics: 25% [250/1000]

edit: I did produce a video showing the effect on the main class of the project, I made a simple pojo class SomeClass

public class SomeClass {
    String someField;

    public SomeClass(String field){
        this.someField = field;
    }

    public String getSomeField() {
        return someField;
    }

    public void setSomeField(String someField) {
        this.someField = someField;
    }
}

Then I made a new void method to construct the new class, trying to fetch any of the getter of setter method inside, and this is the result

https://user-images.githubusercontent.com/1148689/215729955-ed48fef6-d2b6-4908-8311-b7d1c243830f.mp4

This project has been fully developed with vscode and vscode-java with Spring tools one year ago. When I did open it again with a updated vscode it felt like unusable and that's why I started collecting these evidences using a brand new vscode installation.

Other coworkers did clone the same repository and facing the same lag.

francescodedomenico avatar Jan 31 '23 09:01 francescodedomenico

@francescodedomenico do you see this issue when downgrading to 1.13 ? Is it a Maven project, invoking some plugins to process/generate resources?

fbricon avatar Jan 31 '23 10:01 fbricon

@fbricon hi! it's a Gradle project, at the beginning of the project Gradle sync is performed, but that's it, after the initial synchronization I only see the Java build spinning and looping over.

About code generation plugins there is lombok, since the last versions of vscode-java I did disable the dedicated vscode lombok extenion in order to use the one provided by vscode-java. (however the test is performed on a brand new installation where the lombok extension has never been installed so there is no java agent in settings.json)

I tried to downgrade to 1.13 and the situation is slightly better, I can obtain a suggestion after 15-20 seconds and only after deleting and rewriting the whole variable name followed by ".", sometimes I got the suggestion by deleting and rewriting the dot "."

In 1.14 the variable statement results into an unsuccessful java build caused by the unfinished statement itself (the one I'm waiting intellisense to trigger), deleting and rewriting the variable, deleting and rewriting the dot, won't help with intellisense.

francescodedomenico avatar Jan 31 '23 11:01 francescodedomenico

Looks like Java extension is having performance while editing a larger file. Can anyone share the CPU profiling result of Java language server extension?

Here are some steps to profile Java language server extension:

  • Install VisualVM from https://visualvm.github.io/download.html
  • On Local, open the Java extension process "Eclipse".
  • Go to "Profiler" tab page, and profile CPU. For CPU settings, you can configure the Profile classes as "org.eclipse.jdt.**". Please note that for the first profiling, it might take a while to connect to VM, so please be patient.
  • Take Snapshot of collected results, and Export Snapshot Data as *.nps file

image

testforstephen avatar Jan 31 '23 13:01 testforstephen

@testforstephen here's a snapshot of an execution of my own, the profiling stopped curiously when the process ended (and of course I wasn't expecting it to end since vscode and the java project was still opened)

edit: I added a second snapshot showcasing the increasingly number of invocations by publish diagnostics loop

snapshot-1675177368102.zip snapshot-1675178952400.zip

francescodedomenico avatar Jan 31 '23 15:01 francescodedomenico

@snjeza, I cleared my workspace and tried again, same result.

@testforstephen , my project is a maven project which build comptely from scratch by VScode. similar as @francescodedomenico mentioned, when the project size is small, the intellisense made a good performance. However, as more and more lines of codes coming in, the performance dropped dramatically.

I do have some files with 5000+ lines of codes, but the file in video I shared previously only contains 600 lines of codes

@testforstephen , I have also attached my snapshot of an execution of my project. vscode-cpu-snapshot-20230131155823.zip

iamfreeman avatar Feb 01 '23 00:02 iamfreeman

Thank you for sharing the snapshots.

@iamfreeman In your profiling snapshot, I see lombok calls took much CPU time. Could you try to disable the setting java.jdt.ls.lombokSupport.enabled to turn off lombok agent? It requires VS Code reload to take effect.

image

testforstephen avatar Feb 01 '23 13:02 testforstephen