microsoft / TypeScript

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

electron_node tsserver.js using >100 CPU #38329

Closed nickofthyme closed 2 months ago

nickofthyme commented 4 years ago

Issue Type: Bug

Within the last week I have been struggling with vscode/typescript using upwards of 100% CPU. This leads to 10-30 second delays for intellisense for trivial changes.

The main culprit appears to be electron_node tsserver.js.

I've seen a few similar issues but none seem to get the to root of the issue, so apologies if this is a duplicate. This looks similar to https://github.com/microsoft/vscode/issues/96255 but I am experiencing this issue with all extensions disabled.

I first notice the issue using typescript@3.8.3. Then I tried using the nightly build per suggestion here https://github.com/microsoft/TypeScript/issues/34401#issuecomment-541947997. This worked for a day but then the issues resurfaced.

Any help debugging this would be greatly appreciated.

output from code --status after simple code change.

Version:          Code 1.44.2 (ff915844119ce9485abfe8aa9076ec76b5300ddd, 2020-04-16T17:07:18.473Z)
OS Version:       Darwin x64 19.4.0
CPUs:             Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz (16 x 2400)
Memory (System):  32.00GB (0.04GB free)
Load (avg):       3, 2, 2
VM:               0%
Screen Reader:    no
Process Argv:     .
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

CPU %   Mem MB     PID  Process
    0      131   23817  code main
    0       66   23830     gpu-process
    0       33   23832     utility
    0      295   23833     window (portal.tsx — elastic-charts)
    0       98   23836       extensionHost
    0       98   23838         electron_node tsserver.js
  100      623   23839         electron_node tsserver.js
    0       33   23854           electron_node typingsInstaller.js typesMap.js
    0       33   23866         /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=23836
    0       33   23837       watcherService
    0       33   23911       searchService
    0       66   23860     shared-process
    0        0   24878       /bin/ps -ax -o pid=,ppid=,pcpu=,pmem=,command=
    0       66   24847     window (Issue Reporter)

Workspace Stats:
|  Window (portal.tsx — elastic-charts)
|    Folder (elastic-charts): 2705 files
|      File types: ts(640) map(600) png(534) js(314) tsx(307) scss(31) md(17)
|                  json(16) mdx(12) DS_Store(4)
|      Conf files: tsconfig.json(5) webpack.config.js(3) package.json(1)
|                  launch.json(1) settings.json(1)
|      Launch Configs: node(2)

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

System Info |Item|Value| |---|---| |CPUs|Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz (16 x 2400)| |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)|3, 2, 2| |Memory (System)|32.00GB (0.19GB free)| |Process Argv|.| |Screen Reader|no| |VM|0%|
Extensions: none
vscodebot[bot] commented 4 years ago

(Experimental duplicate detection) Thanks for submitting this issue. Please also check if it is already covered by an existing one, like:

Undistraction commented 4 years ago

@nickofthyme seeing the same thing and I've asked to reopen microsoft/vscode#96255

mjbvz commented 4 years ago

@nickofthyme Was the perf log information collected when using the TypeScript nightly extension?

Can you confirm the active TypeScript version by first opening a TS file and then running Select TypeScript version

nickofthyme commented 4 years ago

@mjbvz I don't recall, but I'm pretty sure that was using 3.8.3. I just ran the one below with the nightly extension enabled using typescript@4.0.0-dev.20200503

image

code --status output ``` Version: Code 1.44.2 (ff915844119ce9485abfe8aa9076ec76b5300ddd, 2020-04-16T17:07:18.473Z) OS Version: Darwin x64 19.4.0 CPUs: Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz (16 x 2400) Memory (System): 32.00GB (0.11GB free) Load (avg): 3, 2, 3 VM: 0% Screen Reader: no Process Argv: 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 CPU % Mem MB PID Process 2 131 30708 code main 13 98 30709 gpu-process 0 33 30711 utility 11 295 30712 window (portal.tsx — elastic-charts) 0 66 30986 extensionHost 0 98 31011 electron_node tsserver.js 100 524 31012 electron_node tsserver.js 0 66 31017 electron_node typingsInstaller.js typesMap.js 0 33 31020 /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=30986 0 33 30987 watcherService 0 33 31009 searchService 0 98 31004 shared-process 0 0 31054 /bin/ps -ax -o pid=,ppid=,pcpu=,pmem=,command= Workspace Stats: | Window (portal.tsx — elastic-charts) | Folder (elastic-charts): 2715 files | File types: ts(640) map(600) png(534) js(314) tsx(307) scss(31) md(17) | json(16) mdx(12) xml(6) | Conf files: tsconfig.json(5) webpack.config.js(3) package.json(1) | launch.json(1) settings.json(1) | Launch Configs: node(2) ```
Undistraction commented 4 years ago

@nickofthyme Try checking 'TypeScript: Disable Automatic Type Acquisition' in the settings. That seems to have helped, for me at least.

njprrogers commented 4 years ago

@nickofthyme I saw similar behaviour in a project of mine (nuxt) where I had a .js file present (it was some server middleware) in a .ts application. After excluding the folder in my tsconfig.json, the cpu issues resolved.

nickofthyme commented 4 years ago

@njprrogers what do you mean by present? You experienced this with any *.js file in your code?

Big-Fellow commented 4 years ago

Having similar issue - vs code takes up to 90% CPU, any updates on solution? code --status

Version:          Code 1.46.1 (cd9ea6488829f560dc949a8b2fb789f3cdc05f5d, 2020-06-17T21:13:20.174Z)
OS Version:       Windows_NT x64 10.0.16299
CPUs:             Intel(R) Core(TM) i5-6300U CPU @ 2.40GHz (4 x 2496)
Memory (System):  15.89GB (8.96GB free)
VM:               0%
Screen Reader:    no
Process Argv:     
GPU Status:       2d_canvas:                     enabled
                  flash_3d:                      enabled
                  flash_stage3d:                 enabled
                  flash_stage3d_baseline:        enabled
                  gpu_compositing:               enabled
                  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

CPU %   Mem MB     PID  Process
    0      165   13564  code main
    0       78    9288     shared-process
    0      191   12240     gpu-process
    0       28   12960     utility
    0       16   13676     electron-crash-reporter
    0       68   14212     window (Process Explorer)
    0      194   16144     window (my.component.html - FRONTEND - Visual Studio Code)
    0       92   12956       extensionHost
    0       54     376         electron_node tsserver.js 
    0       55    1524         "C:\DEV\Microsoft VS Code\Code.exe" "c:\DEV\Microsoft VS Code\resources\app\extensions\html-language-features\server\dist\htmlServerMain" --node-ipc --clientProcessId=12956
    0       37    4564         "C:\DEV\Microsoft VS Code\Code.exe" "c:\DEV\Microsoft VS Code\resources\app\extensions\json-language-features\server\dist\jsonServerMain" --node-ipc --clientProcessId=12956
   70      287   14896         electron_node tsserver.js 
    0       47    3372           electron_node typingsInstaller.js typesMap.js 
    0       12   15456       watcherService 
    0       11   14464         console-window-host (Windows internal process)

Workspace Stats: 
|  Window (my.component.html - FRONTEND - Visual Studio Code)
|    Folder (FRONTEND): 4087 files
|      File types: ts(1653) html(1024) scss(287) json(132) svg(71) js(53)
|                  png(29) css(20) md(17) xml(4)
|      Conf files: tsconfig.json(23) tslint.json(21) gulp.js(1)
|                  package.json(1)

Problems appears both on standard and insiders versions.

camnicklaus commented 4 years ago

EDIT: I take it all back... seemed to work for a couple hours but now is behaving like it was before (except that now watcher is running away as well)

Screen Shot 2020-07-07 at 5 06 47 PM

@nickofthyme Try checking 'TypeScript: Disable Automatic Type Acquisition' in the settings. That seems to have helped, for me at least.

worked for me. I'm setting up a new machine, don't have many additional extension installed yet, workspace is large (many directories and files etc) Version: 1.46.1 Commit: cd9ea6488829f560dc949a8b2fb789f3cdc05f5d Date: 2020-06-17T21:17:14.222Z Electron: 7.3.1 Chrome: 78.0.3904.130 Node.js: 12.8.1 V8: 7.8.279.23-electron.0 OS: Darwin x64 19.5.0

nickofthyme commented 4 years ago

Another thing that seemed to help, but less than ideal, is to up the ts-server memory under settings via TypeScript › Tsserver: Max TS Server Memory

image

danbergelt commented 4 years ago

EDIT: After some digging, I stumbled upon this issue https://github.com/microsoft/TypeScript/issues/39284. After removing Ramda from my dependencies, the performance issues went away instantly.

I'm experiencing this as well, on both general release and insiders version. I've tried all suggested solutions, including disabling automatic type acquisition, running without extensions, using the nightly TS extension, etc.

electron_node tsserver.js runs at around 100 CPU for 30 seconds - 1 minute on every minor change before eventually providing intellisense, rendering VSCode pretty much unusable for rapid Typescript development. It's only impacting one project (which isn't huge aside from a fair amount of dependencies, which I've excluded in my tsconfig). If I start a new project everything seems to work just fine.

Version: 1.47.0
Commit: d5e9aa0227e057a60c82568bf31c04730dc15dcd
Date: 2020-07-09T08:01:54.115Z (1 day ago)
Electron: 7.3.2
Chrome: 78.0.3904.130
Node.js: 12.8.1
V8: 7.8.279.23-electron.0
OS: Darwin x64 18.7.0
nickofthyme commented 4 years ago

@RyanCavanaugh What info is needed?

@danbergelt Thanks for the tip! I am not using @types/ramda and removing ramda altogether is not an option as it is a downstream dependency of storybook/core.

@elastic/charts@20.0.2
├─┬ @storybook/react@5.3.19
│ └─┬ @storybook/core@5.3.19
│   └─┬ file-system-cache@1.0.5
│     └── ramda@^0.21.0
brascene commented 3 years ago

Is this issue resolved or no one except me is facing this? I have the same issue, and it started all of a sudden, because during last year VSCode was running very smoothly, with no delays or errors at all, and yesterday it blocked the whole intellisense, autocomplete, imports, everything, it's just stuck in loading state and I can see in that electron_node tsserver or Code Helper (Renderer) process is taking more than 100CPU. I've tried with installing many different (older) versions of VSCode but nothing looks like it's not related with that.

Really don't know what to do, I'm on M1 Mac, project is React Native, Typescript, I have only two extensions (Eslint and Prettier), but even without them I get the same issue.

Any advices/suggestions will be appreciated a lot..

nickofthyme commented 3 years ago

@brascene it comes and goes. Nothing I have done fixes it for good. TS4 was supposed to help but I haven't see any impact good or bad. Eslint seems to be a common denominator not sure if it's related.

Vrq commented 1 year ago

Can the VSCode or TypeScript Team please put some priority into this issue which is open since 3 years? @andrewbranch @a-tarasyuk @jakebailey @sheetalkamat

dgabriele commented 1 year ago

Same issue. Laptop fans are constantly humming. Please look into this. One thing that helps momentarily is restarting the ts server

brascene commented 1 year ago

I commented here a while back, and what I figured out was that it wasn't an issue with VSCode version or some extension, I had a circular dependency mistake in my types.

jakebailey commented 1 year ago

This issue hadn't been updated in more than 2 years; it's pretty unlikely that it's still the same bug, and even so, we really need system info and a reproduction that can be used to diagnose the problem, which has so far not been provided, hence the "Needs More Info" label. Pinging us isn't going to help us figure out the problem if you also don't provide us with new info.

dgabriele commented 7 months ago

This issue hadn't been updated in more than 2 years; it's pretty unlikely that it's still the same bug, and even so, we really need system info and a reproduction that can be used to diagnose the problem, which has so far not been provided, hence the "Needs More Info" label. Pinging us isn't going to help us figure out the problem if you also don't provide us with new info.

What info specifically? I'm not a VSCode or extension developer. If you let me know what log files etc to share, that'd be helpful. Thanks!

jakebailey commented 7 months ago

Do you have a project that we can open and diagnose? Can you provide logs via https://github.com/microsoft/TypeScript/wiki/Getting-logs-from-TS-Server-in-VS-Code ?

nickofthyme commented 6 months ago

I haven't seen this issue in a long time working daily on the same project that caused me to open this issue in the first place.

I'll keep it open as others are interacting with it but if that falls off you can close it.

nickofthyme commented 6 months ago

@ameeli I think they are requesting more than just logs. Sounds like they want a repo they can run to troubleshoot the problem.

The repro should trigger the issue with all extensions disabled.

sheetalkamat commented 6 months ago

@ameeli the log you provided is too small that iit doesnt have any information that can be used for investigation. Please provide repro and full log to be able to investigate this