microsoft / TypeScript

TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
https://www.typescriptlang.org
Apache License 2.0
101.13k stars 12.5k forks source link

TSServer using 100%+ CPU breaking Intellisense, import suggestions etc #38504

Closed Undistraction closed 3 years ago

Undistraction commented 4 years ago

Issue Type: Performance Issue

As soon as I open a JS file and begin editing, TSServer begins using a huge amount of CPU and intellisense etc ceases to function correctly. This happens with all extensions disabled.

My jsconfig.json:

{
  "compilerOptions": {
    "module": "commonjs",
    "target": "es6",
    "jsx": "react"
  },
  "include": ["./src/**/*.js"],
  "exclude": [
    "node_modules",
    "dist",
    "coverage",
    "demo",
    "static",
    "public",
    ".cache"
  ]
}

I'm not using TypeScript, but if I create a .ts file in my project I can see the version is 3.8.3. I have tried installing the JavaScript and Typescript Nightly extension which gives me 4.0.0-dev.20200505 and if anything the performance is worse. Data below was captured with Nightly extension disabled.

I'm running a 2019 Macbook Pro with maxed out specs. At this point VSCode is effectively unusable.

Running ps aux PROCESS ID for the tsserver process:

USER         PID  %CPU %MEM      VSZ    RSS   TT  STAT STARTED      TIME COMMAND
pedrbrowne  6264 158.0  2.6  7101256 866400   ??  R     9:37am   0:48.90 /Applications/Visual Studio Code.app/Contents/Frameworks/Code Helper (Renderer).app/Contents/MacOS/Code Helper (Renderer) --max-old-space-size=3072 /Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js --useInferredProjectPerProjectRoot --enableTelemetry --cancellationPipeName /var/folders/_0/7sk3xl9n18ldl4zswn5_xm6c0000gq/T/vscode-typescript503/e40452cb257dfd4b6c9b/tscancellation-d3202bc4e76652be5db2.tmp* --logVerbosity verbose --logFile /Users/pedrbrowne/Library/Application Support/Code/logs/20200506T093701/exthost1/vscode.typescript-language-features/tsserver-log-s7OhZ6/tsserver.log --globalPlugins typescript-vscode-sh-plugin --pluginProbeLocations /Applications/Visual Studio Code.app/Contents/Resources/app/extensions/typescript-language-features --locale en --noGetErrOnBackgroundUpdate --validateDefaultNpmLocation

This is a follow-on from https://github.com/microsoft/vscode/issues/96255 and possibly related to https://github.com/microsoft/TypeScript/issues/38329

Possibly related: My jsconfig.json file is coloured red in the sidebar. the opening bracket is underlined as an error, and when I roll over the bracket I get this popup (note that axios-mock-adapter is a nested-dependency:

Screenshot 2020-05-06 at 12 25 26

VS Code version: Code 1.44.2 (ff915844119ce9485abfe8aa9076ec76b5300ddd, 2020-04-16T17:07:18.473Z) OS version: Darwin x64 18.7.0

System Info |Item|Value| |---|---| |CPUs|Intel(R) Core(TM) i9-8950HK CPU @ 2.90GHz (12 x 2900)| |GPU Status|2d_canvas: enabled
flash_3d: enabled
flash_stage3d: enabled
flash_stage3d_baseline: enabled
gpu_compositing: enabled
metal: disabled_off
multiple_raster_threads: enabled_on
oop_rasterization: disabled_off
protected_video_decode: unavailable_off
rasterization: enabled
skia_renderer: disabled_off_ok
video_decode: enabled
viz_display_compositor: enabled_on
viz_hit_test_surface_layer: disabled_off_ok
webgl: enabled
webgl2: enabled| |Load (avg)|10, 23, 16| |Memory (System)|32.00GB (1.36GB free)| |Process Argv|| |Screen Reader|no| |VM|0%|
Process Info ``` CPU % Mem MB PID Process 12 131 4804 code main 4 98 4805 gpu-process 0 33 4807 utility 9 295 4808 window (nodeFields.js — sleepstation-public) 0 98 4816 extensionHost 0 66 6248 electron_node tsserver.js 103 918 6264 electron_node tsserver.js 0 98 6549 electron_node typingsInstaller.js typesMap.js 0 33 10475 /Applications/Visual Studio Code.app/Contents/Frameworks/Code Helper (Renderer).app/Contents/MacOS/Code Helper (Renderer) /Applications/Visual Studio Code.app/Contents/Resources/app/extensions/json-language-features/server/dist/jsonServerMain --node-ipc --clientProcessId=4816 0 0 4817 /bin/bash -l 0 33 5411 watcherService 0 33 10759 searchService 0 262 4809 window (.eslintignore — frontend) 0 66 4818 extensionHost 0 0 4823 /bin/bash -l 0 33 4959 watcherService 0 295 4810 window (jest.config.js — sleepstation-admin) 0 66 4828 extensionHost 0 66 5604 electron_node tsserver.js 0 426 5607 electron_node tsserver.js 0 66 5713 electron_node typingsInstaller.js typesMap.js 0 33 10440 /Applications/Visual Studio Code.app/Contents/Frameworks/Code Helper (Renderer).app/Contents/MacOS/Code Helper (Renderer) /Applications/Visual Studio Code.app/Contents/Resources/app/extensions/json-language-features/server/dist/jsonServerMain --node-ipc --clientProcessId=4828 0 0 4829 /bin/bash -l 0 33 5343 watcherService 21 131 5526 shared-process 0 0 10788 /bin/ps -ax -o pid=,ppid=,pcpu=,pmem=,command= 32 66 10786 window (Issue Reporter) ```
Workspace Info ``` | Window (jest.config.js — redacted-admin) | Window (.eslintignore — frontend) | Window (nodeFields.js — redacted-public) | Folder (redacted-public): 4244 files | File types: json(744) js(666) jpg(479) png(443) svg(387) md(246) | pdf(32) DS_Store(29) mp4(24) yml(6) | Conf files: package.json(3) jsconfig.json(1) settings.json(1) | Folder (frontend): 2525 files | File types: js(1538) svg(105) json(46) DS_Store(32) md(27) sh(5) hbs(5) | crt(4) log(3) key(2) | Conf files: package.json(38) jsconfig.json(1) launch.json(1) | settings.json(1) webpack.config.js(1) | Launch Configs: chrome | Folder (redacted-admin): 419 files | File types: js(180) png(55) json(43) md(8) hbs(5) crt(4) DS_Store(2) | yml(2) key(2) ico(2) | Conf files: jsconfig.json(1) package.json(1) webpack.config.js(1) | launch.json(1) settings.json(1) | Launch Configs: chrome; ```

Extensions: none

Undistraction commented 4 years ago

Update: Checking 'TypeScript: Disable Automatic Type Acquisition' appears to have helped.

mjbvz commented 4 years ago

@Undistraction Are you able to share a project that triggers this behavior? Does it seem to be triggered when you open one file in particular?

nickofthyme commented 4 years ago

@mjbvz This project triggers this for me elastic-charts. Any typescript file. If you just start clicking into definitions, you should run into this issue. Let me know if you are not able to repro and I can get more accurate steps to repro.

Note: some of my teammates on the same project have no issues.

Undistraction commented 4 years ago

@mjbvz Happy to share any logs or profiling that might help, but unfortunately I cannot share this project as it is closed-source, however the problem definitely lies with: `'TypeScript: Disable Automatic Type Acquisition'. I've had it checked/disabled for days with only a couple of instances of VSCode locking up (compared to it happening near-permanently before). I just tried checking it again, and pretty much instantly the process jumped to 100%+ cpu and VScode locked up. Rechecking it reversed the issue and VSCode is usable again.

nickofthyme commented 4 years ago

@mjbvz were you able to reproduce the issue? This is a daily issue that comes and goes, forcing me to use IntelliJ.

Undistraction commented 4 years ago

@mjbvz This problem has returned with version 1.46.1, making VSCode almost unusable for me.

moretti commented 4 years ago

I am experiencing the same problem in VSCode 1.46.1 (MacOS 10.15.5). I can see from process explorer that ts-server uses 100% of the CPU. So far the only workaround that I found is to manually kill the process from Activity Monitor.

sheetalkamat commented 3 years ago

I dont seem to be able to repro this with typescript@next I tried the repro given by @nickofthyme but CPU remains at 4-7% as i navigate opening different files. (obviously the first file open takes CPU but it settle downs quickly and other definition navigations dont seem to result in 100%CPU)

Can you please try typescript@next and see if this is fixed. If not we would need tsserver, ti logs and if possible repro steps. Thanks

nickofthyme commented 3 years ago

I haven't noticed this in a while, nor to the severity it was early last year. If I come across it again I will try to create a reproducible example.

nickofthyme commented 3 years ago

I'm having an issue with ts-server again 😫

> code --status
Version:          Code 1.54.1 (f30a9b73e8ffc278e71575118b6bf568f04587c8, 2021-03-04T22:42:18.719Z)
OS Version:       Darwin x64 20.3.0
CPUs:             Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz (16 x 2400)
Memory (System):  32.00GB (0.12GB free)
Load (avg):       3, 3, 3
VM:               0%
Screen Reader:    no
Process Argv:     . --crash-reporter-id 597c34e2-6c90-4a52-adf1-aa1e683b0f95
GPU Status:       2d_canvas:                  enabled
                  gpu_compositing:            enabled
                  metal:                      disabled_off
                  multiple_raster_threads:    enabled_on
                  oop_rasterization:          enabled
                  opengl:                     enabled_on
                  protected_video_decode:     unavailable_off
                  rasterization:              enabled
                  skia_renderer:              disabled_off_ok
                  video_decode:               enabled
                  webgl:                      enabled
                  webgl2:                     enabled

CPU %   Mem MB     PID  Process
    0      131    7510  code main
    0      131    7525     gpu-process
    0       33    7527     utility
    0      426    7528     window (tooltip_portal.tsx — elastic-charts)
    0      328    7529       extensionHost
    0      164    7845         electron_node tsserver.js
  100      786    7846         electron_node tsserver.js
    0       98    7859         electron_node server.js
    0       33    7920         /Applications/Visual Studio Code.app/Contents/Frameworks/Code Helper (Renderer).app/Contents/MacOS/Code Helper (Renderer) /Applications/Visual Studio Code.app/Contents/Resources/app/extensions/json-language-features/server/dist/node/jsonServerMain --node-ipc --clientProcessId=7529
  100      918    7921         electron_node eslintServer.js
    0       33    7532       watcherService
    0       33    7908       searchService
    0       98    7531     shared-process
    0       33    7534       ptyHost
    0        0    7536         zsh -l

Workspace Stats:
|  Window (tooltip_portal.tsx — elastic-charts)
|    Folder (elastic-charts): 3991 files
|      File types: ts(850) map(766) png(761) js(401) tsx(377) html(359)
|                  scss(33) json(23) md(19) mdx(12)
|      Conf files: tsconfig.json(5) webpack.config.js(3) launch.json(1)
|                  settings.json(1) package.json(1)

Unbearably slow, fans running constantly. Tried full restart and get the same result.

@sheetalkamat could you test this using @elastic/charts repo?

Vrq commented 1 year ago

This is an ongoing issue for the last 2 years. It would be nice if someone from the core team finally had a look into it.

AustinBernerEvercast commented 1 year ago

Experiencing the same problem here as well. After auto update of VSC I noticed problems loading type definitions, import suggestions, etc. Searched dozens of existing questions on the topic, and found that the culprit is absolutely tsserver.js. I downgraded to 1.83.1 of VSC for darwin Universal build, but the issue persists.

Every time I enter anything into a TS file (and TS only), this spikes the CPU and locks out intellisense for at least a minute.

Disabled all extensions and this still happens

Enabled this in VSC: TypeScript: Disable Automatic Type Acquisition, and the issue still happens

As others have also done, I've pinpointed the issue to: extensions/node_modules/typescript/lib/tsserver.js

Tried the bisect utility, no extensions were found to cause the issue

Tried using older versions of typescript and VS code, even after removing 100% of modules/components of VSC on my machine

Side note: I experienced this same unfortunate surprise when I started using VSC on my Windows 10 PC, taking my work with me on the go ( VSC also auto-updated here too, I believe).

Result is ALWAYS the same. tsserver.js spiking CPU on every.single.edit.

Update: I also uninstalled any ts packages that were global. Updated Node and NPM. Also found a hidden .vscode at the root and removed that while removing everything else related to VSC. Still nothing :(

Using a different editor now. This is nuts

RyanCavanaugh commented 1 year ago

Hey folks, please log a new issue with repro steps and we'll be happy to investigate. Thanks!