TypeScript: TypeScript server slow - CPU goes up to 160% when waiting for the autocompletion

Does this issue occur when all extensions are disabled?: Yes

  • VS Code Version: Version: 1.61.0-insider (Universal)
  • Operating system:
  • macOS 11.5.2

Steps to Reproduce:

  1. Got a simple Next.js application with react-hook-form installed (not sure if that matters), trying to get autocompletion on their useForm hook. Shows me “Loading…”, takes a couple seconds, and CPU jumps up to 160% in the Activity Monitor. (I also got autocomplete issues on other places, not only on their hook, just used that as an example).
  2. Originally got this issue in the normal version. Switched over to the Insiders version and still got this issue. The project isn’t large and my CPU usage only spikes when I use features from the TypeScript server. I already installed the typescript@next extension and made sure that VSCode uses that version, unfortunately the same issue.

Even saving ts/tsx files can take a couple seconds. And whenever I try to use something that it is not imported, it shows the red line under it. However, when I do import it, it takes a couple seconds before VSCode notices it so the “not imported” error stays there for quite a long time and my CPU usage spikes.

Edit: I recorded a small video that shows when my CPU usage spikes and that VSCode randomly had trouble with importing a few things and that it takes a couple of seconds before it noticed that I already imported it. Also the autocomplete takes a couple of seconds and the CPU usage also spikes on that.

(I am not too sure why VSCode didn’t automatically import the first two hooks, I needed to manually click on them and then it let me import them, as you can see in the video.)

https://user-images.githubusercontent.com/23482089/132833606-1c13bde4-a232-4f11-925f-cedccf7b239c.mov

When using the normal VSCode (not the Insiders version), the autocomplete is even slower and the CPU usage spikes up to 180% (even though all extensions are disabled). I noticed that the fans were going crazy when I was waiting for the autocompletion.

In the Process Explorer, electron_node tsserver.js is the one that spikes.

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Reactions: 9
  • Comments: 15 (5 by maintainers)

Most upvoted comments

@andrewbranch Just tried to put that setting to false in VSCode, unfortunately it doesn’t seem to be effective for me.

However, as soon as I remove the package that has this ajv package, my autocompletion feels much faster than before. I think the issue is also not there when I just don’t import anything from that specific package.

It maybe has something to do with zod, I’ve had seen multiple comments about that crashing TS servers. My issue is completely gone as soon as I remove that package. I’ll try to use 4.2 of TypeScript to see if that solved anything.

The best thing to do is take a performance trace. But I would be shocked if zod isn’t the problem.

@andrewbranch Thanks a lot for your quick response! Totally makes sense. I will look into what’s actually happening and keep you updated.