hashicorp / terraform-ls

Terraform Language Server
Mozilla Public License 2.0
996 stars 131 forks source link

Slow performance on v0.35.0 #1857

Open bcspragu opened 1 week ago

bcspragu commented 1 week ago

Language Server Version

v0.35.0

Terraform Version

v1.9.8

Client Version

helix 24.7 (101a74bf)

Behavior

I'm seeing the same "red squiggle that I can watch recede over ~1 minute" issue I've seen in older versions, while terraform-ls is using 200%+ CPU.

This is on a Terraform workspace with a few hundred resources, so not small, but not massive either. Unfortunately this isn't an open-source repo, but happy to collect metrics or whatever else may be useful.

Steps to Reproduce

  1. Open the terraform/ directory in my (not open-source, sorry) project
  2. Open a few files
  3. Start modifying things

After a few saves/modifications, you'll start seeing things like: image

I've typed a full, valid variable name, but the error will go through various stages of telling me various prefixes of that variable (var.kagi, var.kagi_prox, etc) don't exist, over the course of 10s to 1m.

Meanwhile, I can't save files because Helix is waiting for the LSP formatter to run, which is presumably blocked on these other LSP operations.

Terraform Configuration

Mostly just a standard GCP Terraform config, containing a few of the official Google modules, and a few local modules.

Project Structure

Replacing file names, but otherwise structure is preserved:

.
├── address.tf
├── dir1
│   ├── 1.tf
│   ├── 2.tf
│   ├── 3.tf
│   ├── 4.tf
│   ├── 5.tf
│   ├── 6.tf
│   ├── 7.tf
│   ├── 8.tf
│   ├── 9.tf
│   ├── 10.tf
│   ├── 11.tf
│   ├── 12.tf
│   ├── 13.tf
│   ├── 14.tf
│   ├── 15.tf
│   ├── 16.tf.json
│   ├── 17.tf
│   └── 18.tf
├── 1.tf
├── 2.tf
├── 3.tf
├── 4.tf
├── 5.tf
├── 6.tf
├── 7.tf
├── 8.tf
├── 9.tf
├── 10.tf
├── 11.tf
├── 12.tf
├── 13.tf
├── 14.tf
├── 15.tf
├── 16.tf
├── 17.tf
├── 18.tf
├── 19.tf
├── 20.tf
├── 21.tf
├── 22.tf
├── 23.tf
├── 24.tf
├── 25.tf
├── 26.tf
├── 27.tf
├── 28.tf
├── 29.tf
├── 30.tf
├── 31.tf
├── 32.tf
├── 33.tf
├── 34.tf
├── 35.tf
├── 36.tf
├── 37.tf
├── 38.tf
├── modules
│   ├── dir2
│   │   ├── main.tf
│   │   ├── output.tf
│   │   └── variables.tf
│   ├── dir3
│   │   ├── main.tf
│   │   ├── output.tf
│   │   ├── readme.md
│   │   └── variables.tf
│   ├── docs
│   │   └── src
│   │       ├── dir4
│   │       │   ├── 1
│   │       │   ├── 2.wiki
│   │       │   ├── 3.sh
│   │       │   └── 4.sh
│   │       └── dir5
│   │           ├── 1.yaml
│   │           ├── 2
│   │           ├── 3.old
│   │           ├── 4.py
│   │           ├── 5.sh
│   │           ├── 6.py
│   │           ├── 7.py
│   │           ├── 8.md
│   │           ├── 9.txt
│   │           ├── 10.txt
│   │           ├── 11.sh
│   │           └── 12.sh
│   └── dir6
│       ├── main.tf
│       ├── outputs.tf
│       └── variables.tf
├── 39.tf
├── 40.tf
├── 41.tf
├── 42.tf
├── 43.sh
├── 44.tf
├── 45.tfvars
├── 46.tf
├── 47.tf
├── 48.tf
├── 49.tf
├── 50.tfvars
├── 51.tf
├── 52.tf
├── 53.tf
├── 54.tf
├── 55.tf.json
├── 56.sh
├── 57.out
├── 58.tf
├── 59.tf
└── 60.tf

10 directories, 105 files

Gist

I can grab if this is useful

References

No response

Community Note

dbanck commented 1 week ago

Hi @bcspragu,

Thanks for the report and sorry you're experiencing this slow performance.

Did this happen with the previous version of the language server, or did 0.35.0 introduce it?

bcspragu commented 1 week ago

Great question! This is a new machine/user account/project, so I've only used 0.35.0 on it.

I just installed v0.34.3 to test it out, and v0.34.3 works as expected - I get instant completions and error checking. Flipping back to v0.35.0 and things break again, slow to the point of me not even being sure it was running. So definitely some regression in the most recent version.

I'll use v0.34.3 as a workaround for now!

EDIT: Not that I think it matters, but the v0.35.0 version is coming from the Arch Linux User Repository package, and I installed v0.34.3 from Hashicorp directly. Can test v0.35.0 directly from Hashicorp if that's useful

justinclayton commented 1 week ago

Since OP only had a fresh install, I'll chime in and say that I have the same issue, and first started experiencing this same behavior a few weeks ago, which roughly coincides with my automatic upgrade to v2.33.0 of the Terraform Extension for VS Code, which includes v0.35.0 of terraform-ls. The issue seems to be eliminated by reverting to v0.34.3, by way of installing v2.32.3 of the extension). I'm on macOS 14.7.1 if that's relevant.

dbanck commented 4 days ago

Thank you both for the additional context. Good to hear that using the previous version is a workaround for now.

So far I haven't been able to reproduce the performance regression, but I'll keep investigating.


EDIT: Not that I think it matters, but the v0.35.0 version is coming from the Arch Linux User Repository package, and I installed v0.34.3 from Hashicorp directly. Can test v0.35.0 directly from Hashicorp if that's useful

As a side note, the main difference between the community-built packages (like AUR or homebrew) and those from HashiCorp is that we bundle all official and partner provider schemas in the binary. This allows for a better out-of-the-box experience, as you'll get completion, hover, etc. for most providers without having to run terraform init (or even have terraform installed). But, like you said, I don't think it makes a difference here.

kahlstrm commented 4 days ago

Can also confirm that there seems to be some performance regression on v0.35.0, as opening a repo with 1000+ files (60k+ lines) seems peg the CPU indefinitely (total CPU time was at 4 hours when I stopped).

Reverting to v0.34.3 via reverting to VS Code extension v2.32.3 will result in pegged CPU for a couple of minutes and then it works as normal (total CPU time is under 1 hour). This is what I've had previously as the "expected" behavior.

MacOS 15.1 with an M3 Max.