terraform-ls: High CPU usage since 0.25.0
Server Version
0.25.0
Terraform Version
v1.0.2
Client Version
VSCode 1.62.3
Terraform Configuration Files
N/A perhaps?
Log Output
There’s lot of
2021/12/03 10:09:32 provider_schema.go:196: PSS: getting provider schema in the vscode console log and it seems to be going over and over the repo again and again looking at the whole repo (which has a lot of Terraform in it spread out all over the place)
Expected Behavior
It should work without high CPU
Actual Behavior

The CPU varies from 50-100% consistently while in TF files.
The log when I last copied it had 184491 lines.
Steps to Reproduce
Load some TF files in vscode since the latest update
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 17
- Comments: 39 (17 by maintainers)
@ElvenSpellmaker Thanks for the report and sorry for the experience.
This indexing is generally by design e.g. to enable discovery of cross-module references.
It has a cap on parallelism, but that is mostly just to reduce the peak CPU usage, it just means the indexing will take longer at the cost of lower CPU usage. We have plans to potentially allow this cap to be configurable as per
I would say the easiest short-term solution, while we investigate, would be to open just a few relevant individual folders as opposed to the parent folder which contains many Terraform modules, or to set
"requiredVersion": "0.24.0"in"terraform.languageServer"settings block in VS Code.I would be very interested in the log as it could show us the sequence of operations that happen as part of the indexing. Are you willing to share it? Feel free to encrypt it with my GPG key and send to
radek<at>hashicorp.comif it’s sensitive and you don’t want to post it publicly.I’d like to chime in to say I’m seeing a similar increase in CPU usage/degradation in performance since 0.25.0 got installed. For instance, I’m seeing this CPU usage while the Terraform Formatter is attempting to run on save on a variables file with ~200 LoC and ~60 variables defined in it. It hangs like this for minutes before finishing, unless I cancel it first.
@radeksimko You’ll be receiving an email with the output data in a bit. As far as the CPU profile, I tried configuring the language server as seen in the code block below and something isn’t working correctly. The file gets created, but then nothing gets written to it. I tried a different directory in case there was something weird going on with permissions, and it made no difference.
@radeksimko I emailed a copy of both my memory and cpu profiles
The best way to inspect the profile would be via
go tool pprof, see https://pkg.go.dev/net/http/pprof for more.I suspect this may be related to the signal that is sent to the editor and/or the language server. It will not have any chance to write the CPU profile or do anything if it receives
SIGKILL- at that point it’s just being killed. You could try to findterraform-lsin the process list and try terminating it gracefully from there, or just open your terminal and do it from there:What you see on the top screenshot is the reference count “code lens”, which should be disabled (for all files) and not shown if you have set
terraform.codelens.referenceCounttofalse.Thank you for sending over the log.
I don’t yet entirely understand how that would relate to high CPU usage, but I have a hunch that the flood of the mentioned log messages may be related to the pre-computation of the reference count code lens where we basically attempt to find references across all (initialized) modules in the workspace. It’s worth noting that these lookups are in-memory lookups so they should not consume any significant CPU, but it would likely explain the log messages.
Can you try setting
"terraform.codelens.referenceCount"tofalsein your VS Code settings (only available in the latest extension release2.17.0) and check the log/CPU again?If this continues to be a problem - or either way - can you try to obtain the CPU profile and send it over?
I’ll get the file over to you
EDIT: I’ve just captured a file using
"-log-file=C:\\Users\\JackBlower\\Documents\\terraform-ls-{{pid}}.log",and will get that over, this one is 44k lines so far.