-
Notifications
You must be signed in to change notification settings - Fork 138
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
terraform-ls is using 100% CPU #1527
Comments
Hi @janekolszak, Thanks for taking the time to report this. We're always curious to hear about performance issues in different environments. Can you give us more information about your project structure? Are you opening a large workspace in VS Code? When you open a workspace in VS Code, `terraform-ls' CPU usage usually spikes to 100% for a few seconds as we index the files to build an internal representation of the project structure. I assume you're seeing high CPU usage for a longer period of time? |
I discovered the same with my NeoVIM setup on a M1 Macbook. Whenever the LSP-server is in use, the CPU utilization of terraform-ls is high and responses comes with great delay. The Terraform folder I'm working in has 54 files and 3600 lines of terraform code. On smaller projects, I cannot observe this issue. With version 0.31.5 it works fine, but not with 0.32.0 or 0.32.5. |
Workspace contains couple big projects in golang and infrastructure setup using around 10 terraform repos, each with around 10 files. Ubuntu 22.04.3 CPU is 100% for all the time VSC is open. |
I confirm this is happening to me too quite often, but not always.
But this is clearly not even a workaround: it's a stinky hack. My environment is like this: System: ArchLinuxKernel Version : 6.6.8.zen1-1 terraform-ls0.32.4 terraformTerraform v1.6.6 VSCodeVersion: 1.85.1 VSCode ExtensionHashiCorp Terraform v2.29.1 |
On Linux a solution could be to spawn the language server binary and immediately change its prios with:
This would mitigate the problem, while not really solving it. |
+1 terraform-ls using 700% cpu while working on a big repository with multiple terraform projects/directories. |
+1 Can confirm this is happening on an M2 Macbook Pro using Neovim 0.9.5. The issue started appearing less than a couple of weeks ago. Working on very small projects with very small files. The version of terraform installed on my system currently is 1.7.3 |
@ayofishr small projects with small files sound like an ideal way to reproduce the issue. Would it be possible for you to share that with us? You may also send it privately via email to |
@dbanck Hello Daniel ! Sorry for the late reply. I've had a look at the lsp logs under
{
"start": {
"line": 1,
"character": 785
},
"end": {
"line": 1,
"character": 786
},
"severity": 1,
"source": "Terraform",
"message": "Invalid character: This character is not used within the language."
} My lsp config looks like this lspconfig["terraformls"].setup({
capabilities = capabilities,
on_attach = on_attach,
}) This happens even in the smallest possible projects (ie: a single |
@ayofishr What's the content of line 1? Can you share the first few lines of your configuration? The message indicates that the HCL parser encountered an unsupported token |
@dbanck Nevermind. I manually deleted |
Quick Update. The issue started appearing again yesterday. After bisecting my neovim config, I was able to find the source of the issue. The CPU spike and the errors logged above were caused by After disabling the plugin, everything started working as expected. Hope this helps people who encounter this issue in the future. Thanks again for the wonderful work on this LS 😄 |
@ayofishr Interesting discovery. Thank you for sharing this. |
Marking this issue as stale due to inactivity over the last 30 days. This helps our maintainers find and focus on the active issues. If this issue receives no comments in the next 30 days it will automatically be closed. Maintainers can also remove the stale label. Thank you for understanding. |
I can reproduce the same with the latest
I'm editing a 1000 lines terraform file and the issue is reproducible instantaneously in that project. I enabled logs and found that receiving response for
Inspecting that specific log, the result was empty:
Unfortunately I can't share my code, but would be able to help test out any PR's for fixing this bug. |
+1 Experiencing the exact same things in Neovim, particularly a ton of events are handled quite slowly on every keystroke. Project consists of 30 files, using about 5 providers and referencing >10 modules from GitHub. CPU usage spikes beyond 150%, immediately upon pressing a key after entering insert mode. Outside of insert mode CPU usage is low. Deleting tflint from the LSPs running alongside terraform-ls did not resolve the issue for me. |
We've just released If you have the time, please give it a try and let us know how it works for you. We have tested this with workspaces of different sizes, but still expect some bugs due to the wide variety of configurations. Your feedback is greatly appreciated. |
Thanks! Is there a binary (preferably static) available somewhere that I can test with or do I need to compile it ? |
@psibi Oh sorry, I forgot to mention this. You can get the binary from https://releases.hashicorp.com/terraform-ls/0.34.0-alpha20240611/ |
Thanks, this definitely has improved the situation. I haven't been able to reproduce the bug which was trivially reproducible in the older version of terraform-ls. I will keep an eye on my CPU consumption and update this issue if I'm able to see with the latest alpha version. |
We've shipped the re-architected language server as part of the 0.34.0 stable release last week. The language server will start up much faster and use fewer resources, especially on larger workspaces. I would like to close this issue for now. Please let us know if you experience any problems or regressions. |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. |
Language Server Version
0.32.4
Terraform Version
1.6.5
Client Version
VSC
Behavior
top
saysterraform-ls
uses 100% CPU. This is true for the last couple months.Steps to Reproduce
Open VSC. No terraform file is open.
Terraform Configuration
No response
Project Structure
No response
Gist
No response
References
No response
Community Note
The text was updated successfully, but these errors were encountered: