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

Significant delay in initialization for completion/navigation on open file #2014

Open
ljpsevenc opened this issue Apr 18, 2024 · 3 comments
Open

Comments

@ljpsevenc
Copy link

I use vscode with clangd extension for code completion and navigation, but when I open or reopen a file, it takes a very long time, about 30~60s, for clangd to initialize. The log of the clangd extension is like below:
I[11:32:54.655] <-- textDocument/hover(2699)
I[11:32:54.782] <-- $/cancelRequest
I[11:33:26.077] --> workspace/semanticTokens/refresh(53)
I[11:33:26.077] --> textDocument/clangd.fileStatus
I[11:33:26.080] <-- reply(53)
I[11:33:28.536] --> textDocument/publishDiagnostics
I[11:33:28.556] --> reply:textDocument/documentSymbol(2688) 56891 ms
I[11:33:28.562] --> reply:textDocument/documentHighlight(2689) 56896 ms
I[11:33:28.572] --> reply:textDocument/semanticTokens/full(2690) 56907 ms
I[11:33:28.574] --> reply:textDocument/codeAction(2691) 56909 ms, error: Task was cancelled.
I[11:33:28.574] --> reply:textDocument/documentLink(2692) 56907 ms
I[11:33:28.575] --> reply:textDocument/codeAction(2693) 56731 ms
I[11:33:28.578] --> reply:textDocument/inlayHint(2694) 56378 ms
I[11:33:28.578] --> reply:textDocument/hover(2695) 52978 ms, error: Task was cancelled.
I[11:33:28.578] --> reply:textDocument/hover(2696) 52579 ms, error: Task was cancelled.
I[11:33:28.578] --> reply:textDocument/hover(2697) 51494 ms, error: Task was cancelled.
I[11:33:28.578] --> reply:textDocument/definition(2698) 51394 ms
I[11:33:28.578] --> reply:textDocument/hover(2699) 33923 ms, error: Task was cancelled.
The extension arguments are:
"clangd.arguments": [
"--background-index",
"--clang-tidy",
"--completion-style=detailed",
"--header-insertion=never",
"-j=40",
"--pch-storage=memory"
],
additionally, CPU usage show in htop is low and seems like parallel setting has no effect.

Output of clangd --version:
clangd version 15.0.6
Features: linux
Platform: x86_64-unknown-linux-gnu

Editor/LSP plugin:
vscode/clangd extension

Operating system:
centos7 kernel 3.10.0-1160.el7.x86_64

@HighCommander4
Copy link

A few questions to try to narrow the issue down:

  • Does this happen with all files? Or all files in a particular project? Or a specific file / files in a project?
  • How big (lnes of code) is the affected file? How long does it take to recompile the file when rebuilding after making a change to it?
  • Do you see one CPU core being used heavily during those 30-60 seconds? (It's expected that the -j setting does not make a difference when opening a single file. It mostly has an effect on background indexing which processes multiple files in parallel.)

@ljpsevenc
Copy link
Author

  1. It happens with almost all .cpp files and some headers in a particular project.
  2. Affected files vary from 500 lines to 3000 lines, in the case of .cpp files, the recompile after making change takes about 2~3secs.
  3. Yes.

@HighCommander4
Copy link

the recompile after making change takes about 2~3secs

Are you using clang as your compiler, or something else?

A possible diagnostic step that might produce some interesting information would be to attach the debugger to the clangd process, interrupt it a few times during the 30-60s pause, and get stack traces to see what clangd is doing at that time.

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

No branches or pull requests

2 participants