Skip to content

code completion is really slow with spring-boot-language-server version #282

Closed

Description

@gayanper

When invoking content assist on java files the contents assist is really slow. I have tested this with Eclipse STS4 nightlies and VSCode release as well. They have spring-boot LS versions 1.7.0-SNAPSHOT and 1.6.0-SNAPSHOT respectively. The problem seems to be in 1.7.x version series.

This becomes the problem when working with java files and greatly effect the functionality of intellij when trying to implement the spring boot plugin to intellij. IntelliJ seems to trigger auto completions on typing.

Activity

  1. BoykoAlex commented on Apr 30, 2019

    @BoykoAlex
    Contributor

    I'm not noticing CA in Java file being slow. First invocation in the file ~100ms consequent less than 5ms. Spring Boot LS only produces CA for java files inside @Value annotations.
    Is there a specific project and/or Java file where CA is slow? Can you measure how long Spring Boot LS CA takes? (See SimpleTextDocumentService#completion(CompletionParams))

  2. gayanper commented on Apr 30, 2019

    @gayanper
    ContributorAuthor

    With eclipse i tried this and when the lsp content computor is enabled the normal java content asist becomes slow. But when i disable it its back to normal. I don't see any such delays in the yml and properties contributions

  3. BoykoAlex commented on Apr 30, 2019

    @BoykoAlex
    Contributor

    Enabling/disabling Spring Boot LS from preferences didn't reveal any slow down in CA for me... It doesn't mean there is no issue though.
    Can you check how long Spring Boot LS takes to produce Completion Proposals in your case? Is it just any random CA invocation takes long time in a Java file?

  4. gayanper commented on Apr 30, 2019

    @gayanper
    ContributorAuthor

    Is there a way i can measure without debugging the language server ?

  5. BoykoAlex commented on Apr 30, 2019

    @BoykoAlex
    Contributor

    Measure time in the method and log the calculated time. For example:

    	@Override
    	public CompletableFuture<Either<List<CompletionItem>, CompletionList>> completion(CompletionParams position) {
    		log.info("completion request received");
    		CompletionHandler h = completionHandler;
    		if (h!=null) {
    			try {
    				long t = System.currentTimeMillis();
    				Either<List<CompletionItem>, CompletionList> either = completionHandler.handle(position)
    						.map(Either::<List<CompletionItem>, CompletionList>forRight)
    						.toFuture().get();
    				log.info("Completion Took: {}", System.currentTimeMillis() - t);
    				return CompletableFuture.completedFuture(either);
    			} catch (InterruptedException e) {
    				// TODO Auto-generated catch block
    				e.printStackTrace();
    			} catch (ExecutionException e) {
    				// TODO Auto-generated catch block
    				e.printStackTrace();
    			}
    		}
    		return CompletableFuture.completedFuture(Either.forRight(NO_COMPLETIONS));
    	}
    
  6. BoykoAlex commented on Apr 30, 2019

    @BoykoAlex
    Contributor

    Is it just the CA that is slow? Or is it a general IDE slow down? If it generally becomes sluggish with Boot LS running heap dumps when it is slow would help too.
    Also check if SimpleTextDocumentService#resolveCompletionItem(CompletionItem) is getting called numerous times. Ideally it should only be called (request sent from the client) for the currently selected completion item. If it's called for all then it's a serious bug.

  7. gayanper commented on Apr 30, 2019

    @gayanper
    ContributorAuthor

    The log you mentioned, how can i enabled it to be shown in Language Server Console in eclipse ?

  8. BoykoAlex commented on Apr 30, 2019

    @BoykoAlex
    Contributor

    Eclipse Preferences: Language Servers -> Spring Language Servers. Now you should see the check boxes for STS LS plugins. Check Spring Boot (or any other) to the see the log of the LS process in the Eclipse Console view.

  9. gayanper commented on Apr 30, 2019

    @gayanper
    ContributorAuthor
    22:39:01.821 [pool-3-thread-1] INFO  o.s.i.v.c.l.u.SimpleTextDocumentService - completion request received
    22:39:01.835 [elastic-3] INFO  o.s.i.v.c.l.c.VscodeCompletionEngineAdapter - Starting completion handling
    22:39:05.146 [elastic-3] INFO  o.s.i.v.c.l.c.VscodeCompletionEngineAdapter - Got 0 completions
    22:39:05.151 [elastic-3] INFO  o.s.i.v.c.l.c.VscodeCompletionEngineAdapter - Completion handling terminated!
    

    This was the output. Seems like the completions take nearly 4 seconds to results a empty completion list. This is initial completion

  10. gayanper commented on Apr 30, 2019

    @gayanper
    ContributorAuthor
    22:41:25.034 [pool-3-thread-1] INFO  o.s.i.v.c.l.u.SimpleTextDocumentService - completion request received
    22:41:25.039 [elastic-8] INFO  o.s.i.v.c.l.c.VscodeCompletionEngineAdapter - Starting completion handling
    22:41:25.764 [elastic-8] INFO  o.s.i.v.c.l.c.VscodeCompletionEngineAdapter - Got 0 completions
    22:41:25.765 [elastic-8] INFO  o.s.i.v.c.l.c.VscodeCompletionEngineAdapter - Completion handling terminated!
    

    This is the second completion request, which also takes around 700ms

  11. gayanper commented on Apr 30, 2019

    @gayanper
    ContributorAuthor
    22:43:06.421 [pool-3-thread-1] INFO  o.s.i.v.c.l.u.SimpleTextDocumentService - completion request received
    22:43:07.850 [elastic-9] INFO  o.s.i.v.c.l.c.VscodeCompletionEngineAdapter - Starting completion handling
    22:43:09.659 [elastic-9] INFO  o.s.i.v.c.l.c.VscodeCompletionEngineAdapter - Got 0 completions
    22:43:09.666 [elastic-9] INFO  o.s.i.v.c.l.c.VscodeCompletionEngineAdapter - Completion handling terminated!
    

    This is a new different completion request on the same started IDE without closing the file even.

  12. BoykoAlex commented on Apr 30, 2019

    @BoykoAlex
    Contributor

    Where is the 4 seconds it took for completion got logged? It should be between those lines... Do you log the calculated time? If the code is similar to the snippet i pasted above the time should be logged...
    Feels like you didn't rebuild the LS jars... From eclipse-language-servers folder run ./local-build.sh wait until it's completed then re-launch the runtime workbench.

  13. gayanper commented on Apr 30, 2019

    @gayanper
    ContributorAuthor

    No i didn't changed the source code. Well at least we can see there is some delay since the log time is the time the log entry was created rather than the time it was written to file right ?

  14. kdvolder commented on Apr 30, 2019

    @kdvolder
    Member

    Seems like @gayanper clearly is experiencing long delay for boot language server to return '0 completions'. The timestamp in the log output are indeed good enough evidence to prove that.

    The question is now... why? To find out more it will probably be necessary to add some additional logging during the processing.

  15. BoykoAlex commented on Apr 30, 2019

    @BoykoAlex
    Contributor

    Yes, indeed from the time of the log entries it does take long... doesn't take as long for me. It'd be great if you could dig into the code a bit and see what exactly takes all that time on the Boot LS. Simply measuring the time method execution takes will point in the right direction... Would be good to know how long it takes for BootJavaCompletionEngine#getCompletions(...) for example...
    Otherwise, it'd be good to have the project you're trying. the Java file as well. Any specific places that are having slow CA? What's the JVM running the LS process? Are you on Win, Mac or Linux?

    I get for CA:

    13:26:06.094 [pool-3-thread-1] INFO  o.s.i.v.c.l.u.SimpleTextDocumentService - completion request received
    13:26:06.099 [elastic-5] INFO  o.s.i.v.c.l.c.VscodeCompletionEngineAdapter - Starting completion handling
    13:26:06.108 [elastic-5] INFO  o.s.i.v.c.l.c.VscodeCompletionEngineAdapter - Got 0 completions
    13:26:06.110 [elastic-5] INFO  o.s.i.v.c.l.c.VscodeCompletionEngineAdapter - Completion handling terminated!
    13:26:07.391 [pool-3-thread-1] INFO  o.s.i.v.c.l.u.SimpleTextDocumentService - completion request received
    13:26:07.392 [elastic-2] INFO  o.s.i.v.c.l.c.VscodeCompletionEngineAdapter - Starting completion handling
    13:26:07.455 [ForkJoinPool.commonPool-worker-15] INFO  o.s.i.v.c.boot.app.cli.SpringBootApp - check for spring jmx beans (retry no. 1) -- LocalSpringBootApp [id=46595, name=``]
    13:26:07.456 [ForkJoinPool.commonPool-worker-3] INFO  o.s.i.v.c.boot.app.cli.SpringBootApp - check for spring jmx beans (retry no. 1) -- LocalSpringBootApp [id=51885, name=``]
    13:26:07.456 [ForkJoinPool.commonPool-worker-7] INFO  o.s.i.v.c.boot.app.cli.SpringBootApp - check for spring jmx beans (retry no. 1) -- LocalSpringBootApp [id=81619, name=``]
    13:26:07.472 [elastic-2] INFO  o.s.i.v.c.l.c.VscodeCompletionEngineAdapter - Got 0 completions
    13:26:07.472 [elastic-2] INFO  o.s.i.v.c.l.c.VscodeCompletionEngineAdapter - Completion handling terminated!
    13:26:09.737 [pool-3-thread-1] INFO  o.s.i.v.c.l.u.SimpleTextDocumentService - completion request received
    13:26:09.738 [elastic-5] INFO  o.s.i.v.c.l.c.VscodeCompletionEngineAdapter - Starting completion handling
    13:26:09.740 [elastic-5] INFO  o.s.i.v.c.l.c.VscodeCompletionEngineAdapter - Got 0 completions
    13:26:09.740 [elastic-5] INFO  o.s.i.v.c.l.c.VscodeCompletionEngineAdapter - Completion handling terminated!
    

    Looks fast. Trying to figure out what is different in your setup.

  16. 24 remaining items

  17. BoykoAlex commented on May 2, 2019

    @BoykoAlex
    Contributor

    Hopefully fixed with 6163411

  18. gayanper commented on May 3, 2019

    @gayanper
    ContributorAuthor

    @BoykoAlex @kdvolder Windows 10 results
    Execution1
    image

    Execution2
    image

  19. gayanper commented on May 3, 2019

    @gayanper
    ContributorAuthor

    Some benchmarks which shows the current direction is the right direction :)

    Benchmark Mode Samples Mean Mean error Units
    o.t.p.MyBenchmark.testFile avgt 10 478.075 337.285 ms/op
    o.t.p.MyBenchmark.testRegex avgt 10 724.041 266.221 ms/op
  20. BoykoAlex commented on May 6, 2019

    @BoykoAlex
    Contributor

    I think we are ok to close this

  21. d2k2-git commented on Sep 24, 2019

    @d2k2-git

    @martinlippert I am using STS 4.4.0 (win10 x64, eclipse 4.13, openjdk 12). i had a lot of freezes in the past weeks when using the code assistant or combined hover. Today i disabled the spring boot "language server" for Java source files and the freezes are gone. Does the Language Server require a permanent stable internet connection? i am using STS behind a proxy in the company i work at. could that be a problem?

    i could also not find any documentation about this option and was also not able to spot a difference in the code assitant after i disabled the language server.

  22. BoykoAlex commented on Sep 24, 2019

    @BoykoAlex
    Contributor

    @d2k2-git lets move this discussion over to #370
    Is your OS Windows?
    Is your STS 4.4.0 based on Eclipse 4.12 or 4.13?
    What do you see in the Boot Language Server log? Can you paste it here? (Should see the log in Console view if you have enabled Boot Languege Server logging in the console view via preferences)
    Can you profile content assist invocation with VisualVM (CPU sampling) and attach the profiling file here?

    Please reply with more info in #370. Thanks in advance!

  23. BoykoAlex commented on Sep 24, 2019

    @BoykoAlex
    Contributor

    @d2k2-git actually never mind #370. It's about Ctrl-Click navigation... it might be unrelated to CA being slow... Please comment here :-)

  24. kdvolder commented on Sep 24, 2019

    @kdvolder
    Member

    Does the Language Server require a permanent stable internet connection? i am using STS behind a proxy in the company i work at. could that be a problem?

    Not explicitly or by design. But I have been surprised in the past that sometimes even just using localhost connecions can end-up somehow pinging outside internet. I recall somethings related to domain name and/or reverse domain name resolution being called from inside Java's socket apis causing delays in the past. So I wouldn't rule out that the firewalling situation in your network has this kind of an effect.

  25. martinlippert commented on Sep 25, 2019

    @martinlippert
    Member

    @d2k2-git Maybe it is nevertheless related to #370, at least you could try to enable the logging to the console via Preferences -> Language Server -> Spring Language Server and activate the logging for the Spring Boot LS there. Maybe it reveals anything interesting on the console, like a similar exception than in #370.

  26. d2k2-git commented on Sep 27, 2019

    @d2k2-git

    So far i was not able to find any interesting information from the log files. i will have time in arround 10 days to invetigate this problem. i would like to help you. but i need some detailed instruction how to perform the thread/memory snapshots you need. i already tried to do myself, but eclipse is not even listed in jprofiler or visualvm. in jconsole i could not find any dumping/snapshot option.

  27. BoykoAlex commented on Sep 27, 2019

    @BoykoAlex
    Contributor

    @d2k2-git
    VisualVM

    1. Download from https://visualvm.github.io/
    2. Start STS 4.4.0, open Java file from Spring Boot project
    3. Start Visual VM. You should see in the left pane the following:
      Screen Shot 2019-09-27 at 11 19 41
    4. Then click on the Sample toggle button at the top of the right pane. You should see on the next row CPU and Stop buttons:
      Screen Shot 2019-09-27 at 11 21 00
    5. Click on CPU button (starts sampling). Gp to Eclipse and activate time consuming content assist proposals computation. Wait until proposal computed or Eclipse freezes and then click Stop button in VisualVM.
    6. Click on the Snapshot button
      Screen Shot 2019-09-27 at 11 30 13
    7. Now you should see the snapshot under the app in the left pane
      Screen Shot 2019-09-27 at 11 31 42
    8. Right-click on that snapshot and click on Save As...
    9. Attach the saved .nps file for profiled Eclipse here.
      Repeat the same steps for the Boot LS process: org.springframeework.ide.vscode.boot.app.BootLanguageServerBootApp and attach .nps file for the Boot LS profiling here as well.
  28. d2k2-git commented on Oct 11, 2019

    @d2k2-git

    @BoykoAlex
    Sorry for the late answear. i try to follow your instruction to make a snapshot with visualVM. But there is no eclipse and bootLanguageServer process listed in VisualVM. i tested with different JDK combinations, but no luck.

    I can only confirm that STS is now running for many days without freeze when using the content assistant since i disabled the LanguageServer for Java source files.

    I still wonder what i am missing after disabling the languagse server for java source files. i did not notice any difference while using the content assistant.

  29. kdvolder commented on Oct 15, 2019

    @kdvolder
    Member

    I still wonder what i am missing after disabling the languagse server for java source files. i did not notice any difference while using the content assistant.

    The language server doesn't do much in terms of content assist in Java files. There is one example where it kicks in that is inside of @Value(...) annotations. Of the top of my head there's nothing else that comes to mind. The language server does other things though such as providing boot specific symbols in 'open symbols' dialog (press CTRL-6 to open it). Hovers for live process data, completions for properties while editing application.properties and application.yml.

    If you are not interested in any of those features then you are probably not missing anything disabling the language server.

    @d2k2-git
    In the recent past we have seen several reports similar to yours from people on windows and in many cases the problem was caused by them using the built-in windows zip utility to unpack STS distribution. The zip utility in Windows does not support long path names out of the box and just unpacks STS incorrectly causing the language server in particular to break.

    See: #304

    If you are on Windows and this sounds like it could be your problem, then maybe you can try some of the worksarounds described in that ticket. TLDR: unpack it using something else like jar xf ... on the CLI or 7zip.

  30. d2k2-git commented on Oct 17, 2019

    @d2k2-git

    In the recent past we have seen several reports similar to yours from people on windows and in many cases the problem was caused by them using the built-in windows zip utility to unpack STS distribution. The zip utility in Windows does not support long path names out of the box and just unpacks STS incorrectly causing the language server in particular to break.

    @kdvolder
    thx for your answear. STS was unpacked with 7zip on my system.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions