language-tools: Extension slow to respond

Describe the bug Getting auto-completion, symbol navigation or symbol information can be very slow (tooltip stuck on Loading...). (It is probably the language server, because the profile from “Running Extensions” does not pick it up as causing CPU load.)

To Reproduce Invoke commands like “Trigger Suggest” and “Go to Definition”.

As for the conditions necessary to cause the slowdown, i am not sure. It may have to do with using carbon-components-svelte/carbon-icons-svelte which introduce a lot of Svelte files. The “Output” panel shows this for Svelte:

SnapshotManager File Statistics:
Project files: 26022
Svelte files: 7210
From node_modules: 33251
Total: 33276

Expected behavior Language features are reasonably fast.

Screenshots image

System (please complete the following information):

  • OS: Windows 10, 64bit
  • IDE: VSCode
  • Plugin/Package: Svelte for VSCode

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Comments: 59 (29 by maintainers)

Commits related to this issue

Most upvoted comments

Please open a separate issue with reproduction on the problematic HTML. Usually, the ts/js part is much more heavy because the cross-file semantic analysis is needed. If I have to make a wild guess, it may be that your style tag or template preprocess is too heavy.

+1. Steps to produce:

  1. Create a 2,200 line Svelte file
  2. Import a basic store
  3. Use option+space on the store to trigger intellisense autocomplete store.<methods hopefully here>

I wish I could provide a better reproducable example but the project seems to need to be of sufficient size to trigger whatever rapid degradation in performance is occurring. As you can see from the log below, the code action takes 11 seconds to complete on an M1 Macbook Pro. Svelte may be trying to do too much work on its end rather than simply proxying to the TS server. The tsconfig explicitly ignores node_modules but they’re showing up in the snapshot.

Trace - 00:41:47] Sending request 'textDocument/completion - (5264)'.
[Trace - 00:41:47] Sending request 'textDocument/codeAction - (5265)'.
Using Svelte v3.56.0 from /Users/cm/ws/svelte-frontend/node_modules/svelte/compiler
[Trace - 00:41:48] Sending notification '$/cancelRequest'.
[Trace - 00:41:48] Sending request 'textDocument/completion - (5266)'.
[Trace - 00:41:48] Sending notification '$/cancelRequest'.
[Trace - 00:41:48] Sending request 'textDocument/inlayHint - (5267)'.
[ts] getCompletionData: Get current token: 0.004291057586669922
[ts] getCompletionData: Is inside comment: 0.018208026885986328
[ts] getCompletionData: Get previous token: 0.027250051498413086
[ts] getCompletionsAtPosition: isCompletionListBlocker: 0.00787496566772461
[ts] getExportInfoMap: cache miss or empty; calculating new results
[ts] getExportInfoMap: done in 16.80887508392334 ms
[ts] collectAutoImports: resolved 0 module specifiers, plus 0 ambient and 127 from cache
[ts] collectAutoImports: response is incomplete
[ts] collectAutoImports: 9.609333992004395
[ts] getCompletionData: Semantic work: 28.18766689300537
[ts] getCompletionsAtPosition: getCompletionEntriesFromSymbols: 4.0915000438690186
[Trace - 00:41:50] Received notification 'textDocument/publishDiagnostics'.
[Trace - 00:41:50] Sending request 'textDocument/codeAction - (5268)'.
[Trace - 00:41:50] Sending notification '$/cancelRequest'.
Using Svelte v3.56.0 from /Users/cm/ws/svelte-frontend/node_modules/svelte/compiler
Using Svelte v3.56.0 from /Users/cm/ws/svelte-frontend/node_modules/svelte/compiler
[Trace - 00:41:52] Sending request 'textDocument/documentSymbol - (5269)'.
Using Svelte v3.56.0 from /Users/cm/ws/svelte-frontend/node_modules/svelte/compiler
Using Svelte v3.56.0 from /Users/cm/ws/svelte-frontend/node_modules/svelte/compiler
Using Prettier v2.8.8 from /Users/cm/ws/svelte-frontend/node_modules/prettier
[ts] getCompletionData: Get current token: 0.004541873931884766
[ts] getCompletionData: Is inside comment: 0.023833036422729492
[ts] getCompletionData: Get previous token: 0.016124963760375977
[ts] getCompletionsAtPosition: isCompletionListBlocker: 0.001708984375
[ts] getCompletionData: Semantic work: 0.24299979209899902
[ts] getCompletionsAtPosition: getCompletionEntriesFromSymbols: 0.1382920742034912
[Trace - 00:41:57] Received response 'textDocument/completion - (5259)' in 13755ms.
[Trace - 00:41:57] Received response 'textDocument/codeAction - (5260)' in 12723ms.
[Trace - 00:41:57] Received notification 'textDocument/publishDiagnostics'.
[Trace - 00:41:57] Received response 'textDocument/semanticTokens/full - (5261)' in 12719ms.
[Trace - 00:41:57] Received response 'textDocument/inlayHint - (5262)' in 11725ms.
[Trace - 00:41:57] Received response 'textDocument/codeAction - (5263)' in 11479ms.
[Trace - 00:41:57] Received response 'textDocument/completion - (5264)' in 10208ms.
[Trace - 00:41:57] Received notification 'textDocument/publishDiagnostics'.
[Trace - 00:41:57] Received response 'textDocument/codeAction - (5265)' in 9960ms.
[Trace - 00:41:57] Received response 'textDocument/inlayHint - (5267)' in 8960ms.
[Trace - 00:41:57] Received response 'textDocument/completion - (5266)' in 9331ms.
[Trace - 00:41:57] Received response 'textDocument/codeAction - (5268)' in 7570ms.
[Trace - 00:41:58] Sending request 'textDocument/codeAction - (5270)'.
[Trace - 00:41:58] Received response 'textDocument/codeAction - (5270)' in 1ms.
[Trace - 00:41:58] Received response 'textDocument/documentSymbol - (5269)' in 6474ms.
[Trace - 00:41:59] Sending request 'textDocument/semanticTokens/full - (5271)'.
[Trace - 00:41:59] Received response 'textDocument/semanticTokens/full - (5271)' in 3ms

Snapshot

SnapshotManager File Statistics:
Project files: 60
Svelte files: 52
From node_modules: 478
Total: 542

Here’s the tsconfig:

{
  "extends": "@tsconfig/svelte/tsconfig.json",

  "include": ["src/**/*"],
  "exclude": ["node_modules/*", "__sapper__/*", "public/*"]
}

I ran into this as well, but just only on large files, which at least around 1k lines.

  System:
    OS: Linux 5.15 Ubuntu 20.04.4 LTS (Focal Fossa)
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
    Memory: 6.45 GB / 15.48 GB
    Container: Yes
    Shell: 5.0.17 - /bin/bash
  Binaries:
    Node: 18.15.0 - ~/.nvm/versions/node/v18.15.0/bin/node
    npm: 9.4.0 - ~/node_modules/.bin/npm
  Browsers:
    Chrome: 111.0.5563.110
    Firefox: 111.0.1
  npmPackages:
    @sveltejs/adapter-static: ^2.0.1 => 2.0.1 
    @sveltejs/kit: ^1.14.0 => 1.14.0 
    svelte: ^3.57.0 => 3.57.0 
    vite: ^4.2.1 => 4.2.1 

Same here with 1.5K lines:

  System:
    OS: Windows 10 10.0.19045
    CPU: (12) x64 AMD Ryzen 5 5600X 6-Core Processor
    Memory: 14.76 GB / 31.91 GB
  Binaries:
    Node: 16.13.0 - C:\Program Files\nodejs\node.EXE
    npm: 8.4.1 - ~\node_modules\.bin\npm.CMD
  Browsers:
    Edge: Spartan (44.19041.1266.0), Chromium (112.0.1722.39)
  npmPackages:
    svelte: ^3.58.0 => 3.58.0
    svelte-check: ^3.0.3 => 3.0.3
    svelte-preprocess: ^5.0.1 => 5.0.1
    typescript: ^4.9.5 => 4.9.5

Did you manage to fix it?

My apologies, I should have provided better feedback than that 🥲

I am not using the transformation. I have disabled diagnostics. I am using the latest svelte extension.

I have fixed my problem by changing my project dependencies packages versions…would have to pinpoint which one was causing the issue. Updated deps:

svelte-preprocess@4.10.1=>4.9.8 This is a rollback svelte@3.44.0=>3.46.3 typescript@4.4.3=>4.5.5

After making these changes, the extension is now working fine.

Ok, so I also did not see this reproduce when I tried in in VSCode proper, but I did figure out my particular issue.

Since svelte-language-server is linked to typescript@*, yarn was just never upgrading it in coc-svelte and it was still pointing to version 4.1.3. There have been a bunch of performance fixes in typescript for pnpm repositories, and indeed, after forcing it to upgrade to latest typescript it’s just as fast with pnpm as with yarn.

Unfortunately this won’t really help anyone else having performance issues, but consider my problems done 😃. I am still seeing it slow with both Neovim and VSCode on really large Svelte files (like 2000 lines) with tons of reactive statements, but that’s less concerning.

Ah, I’m using Linux, Ubuntu 21.04, so that’s probably related… The pnpm/yarn difference makes me think it’s something related to symlinks, and so the Linux/Windows difference could be relevant here 😃. Using svelte-language-server 0.14.8, but I can try with VSCode as well.

Thanks for the link to the setup instructions. I’m pretty sure I can look into this further over the next few days so I’ll hopefully have some updates soon!

In my experience PNPM is a significant factor here. I’ve been seeing performance problems in the autocomplete as well and if I install my project’s dependencies with Yarn instead then it’s a lot faster. 5-7 seconds with pnpm compared to a second or so with Yarn on my system. And this only happens in Svelte files; plain Typescript files perform great.

The public project I’m working on that exposes this the most is at https://github.com/dimfeld/ergo. It’s not really minimal but hopefully it’ll help. The specific steps I’m doing are:

  1. Clone the repo
  2. cd web
  3. pnpm i
  4. Open src/components/Query.svelte.
  5. Somewhere in the file, start to type “delayedLoading” (a variable declared in the component) and see the slowness.

I’m actually using Neovim but my language server dependencies are up to date. I wouldn’t expect VS Code to be any different here.

If I have some time this week I’ll try to dive in more to see where exactly in the language server internals is running slowly.

This does not use sapper or svelte-kit. Have a look at what carbon-icons-svelte exposes: https://unpkg.com/carbon-icons-svelte@10.36.0/lib/index.js All of those are separate .svelte files.

If i were to exclude that, i would lose the completion for that, though, right?