microsoft / TypeScript

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

tsserver.js using too much memory #30034

Closed Meisolsson closed 3 years ago

Meisolsson commented 5 years ago

Issue Type: Performance Issue

After running the editor for a while tsserver uses more and more memory with only 3-4 files open at the time

VS Code version: Code 1.30.2 (61122f88f0bf01e2ac16bdb9e1bc4571755f5bd8, 2019-01-07T22:48:31.260Z) OS version: Darwin x64 18.2.0

System Info |Item|Value| |---|---| |CPUs|Intel(R) Core(TM) i5-4278U CPU @ 2.60GHz (4 x 2600)| |GPU Status|2d_canvas: enabled
checker_imaging: disabled_off
flash_3d: enabled
flash_stage3d: enabled
flash_stage3d_baseline: enabled
gpu_compositing: enabled
multiple_raster_threads: enabled_on
native_gpu_memory_buffers: enabled
rasterization: enabled
video_decode: enabled
video_encode: enabled
webgl: enabled
webgl2: enabled| |Load (avg)|3, 3, 3| |Memory (System)|8.00GB (0.04GB free)| |Process Argv|| |Screen Reader|no| |VM|0%|
Process Info ``` CPU % Mem MB PID Process 15 82 48248 code main 0 106 48249 gpu-process 0 25 48457 shared-process 0 311 58478 window (types.js — keyruler (Workspace)) 0 0 58479 /bin/bash -l 0 82 58518 extensionHost 0 1720 58687 electron_node tsserver.js 0 25 58722 electron_node typingsInstaller.js typesMap.js 0 16 58684 watcherService 0 33 61982 /Applications/Visual Studio Code.app/Contents/Frameworks/Code Helper.app/Contents/MacOS/Code Helper /Applications/Visual Studio Code.app/Contents/Resources/app/out/bootstrap-fork ms-vscode.node2 {"common.vscodemachineid":"aa09937a8f20affad38b2536d7c6d608be681a06011c1b9cc89ab3faa2635ecc","common.vscodesessionid":"8bc62413-df46-45fb-a6b9-60ee4e7fd3691549297291928"} AIF-d9b70cd4-b9f9-4d70-929b-a071c400b217 2 74 62679 window (Issue Reporter) 0 0 62682 /bin/ps -ax -o pid=,ppid=,pcpu=,pmem=,command= ```
Workspace Info ``` | Window (types.js — keyruler (Workspace)) | Folder (keyruler): 6 files | File types: json(2) md(1) gitignore(1) js(1) | Conf files: package.json(1) | Folder (kafka-avro): 26 files | File types: js(12) yml(4) json(4) editorconfig(1) gitignore(1) nvmrc(1) | md(1) opts(1) | Conf files: package.json(1) | Folder (avsc): 147 files | File types: js(39) json(31) avsc(20) py(6) avdl(5) md(5) png(5) java(4) | proto(4) avro(3) | Conf files: package.json(3) launch.json(1) | Launch Configs: node; ```

Extensions: none

mjbvz commented 5 years ago

Does this reproduce in the latest VS Code insiders build with all extensions disabled?

ourcore commented 5 years ago

I was about to report the same issue. Not sure if I still should since it's similar, but not identical.

My processes look a little different:

CPU %   Memory (MB) pid Name
7   98  59412   code main
11  66  59447        gpu-process
0   82  59451        shared-process
20  311 59570        window (index.html)
100 197 59572            extensionHost
0   115 59575                /Applications/Visual Studio Code.app/Contents/Frameworks/Code Helper.app/Contents/MacOS/Code Helper /Applications/Visual Studio Code.app/Contents/Resources/app/extensions/html-language-features/server/dist/htmlServerMain --node-ipc --clientProcessId=59572
0   66  59576                /Applications/Visual Studio Code.app/Contents/Frameworks/Code Helper.app/Contents/MacOS/Code Helper /Applications/Visual Studio Code.app/Contents/Resources/app/extensions/css-language-features/server/dist/cssServerMain --node-ipc --clientProcessId=59572
0   197 59955                electron_node tsserver.js 
0   66  59959                    electron_node typingsInstaller.js typesMap.js 
0   49  59573            watcherService
0   49  59587            searchService
0   66  62875        window (Process Explorer)
0   0   62915            /bin/ps -ax -o pid=,ppid=,pcpu=,pmem=,command=
mjbvz commented 5 years ago

@ourcore Please open a different issue. From that sample it doesn't look like TS server is using much cpu or memory

Meisolsson commented 5 years ago

@mjbvz This is with the latest insiders build, no extensions.

Some more things that i notices is that it goes up while running Format Document, might be after other tasks as well but thats the one I stumbled on. The files I have open are about 4000 lines each. The memory usage does go down a little bit after a while but it's still att 1500 MB after about 5m of doing nothing.

CPU %   Mem MB     PID  Process
   17       98   65815  code-insiders main
    0       66   65817     gpu-process
    1      336   65820     window (test_types.js — keyruler (Workspace))
    0        0   66036       /bin/bash -l
    0       66   66110       extensionHost
    0     1982   66252         electron_node tsserver.js 
    0       25   66291           electron_node typingsInstaller.js typesMap.js 
    0       25   66243       watcherService
    0       49   66033     shared-process
    0       74   69484     window (Issue Reporter)
    0        0   69486     /bin/ps -ax -o pid=,ppid=,pcpu=,pmem=,command=
mjbvz commented 5 years ago

Approximately how many files and how many lines of code do you have open?

Meisolsson commented 5 years ago

Two files each about 4000 lines.

mjbvz commented 5 years ago

Can you share those files or the project? Are they part of a large project (with node_modules)?

Meisolsson commented 5 years ago

It's a modified version of https://github.com/mtth/avsc, the files are lib/types.js and test/test_types.js. My files are a bit longer due to some modifications which are not public yet, when they are I can share those too, but that shouldn't make a big difference.

mjbvz commented 5 years ago

Thank you for the example project @Meisolsson. I just tested this in the latest VS Code insiders build and have not been able to make memory increase past around 300mb after opening most of the files in the project and making a few edits in them

A few other questions to help us investigate this:

mattch commented 5 years ago

I'm having the same issue, though for me the cpu and memory spikes are sporadic. Once the start, they usually won't go away until I restart vscode. When I'm not seeing the problem, there doesn't seem to be any way to make it happen. I've tried opening a dozen large files without any spike in cpu or memory.

I have the latest vscode and typescript.

sheetalkamat commented 5 years ago

@mattch Please share the tsserver log and ti log using vscode insiders latest build and using typescript nightly drop when the issue repros. You can upload logs by following these steps:

  1. With "typescript.tsserver.log": "verbose" enabled
  2. Restart vscode or vscode insiders
  3. Reproduce the problem
  4. You can share the logs using
    • either by sharing logs in the folder that gets opened by running open tsserver log from command palette or
    • Run code --upload-logs on the command line (or code-insiders --upload-logs if using vscode insiders) and follow instructions and Then share the log file ID
delroh commented 5 years ago

Same issue happening to to me, on Windows 10. Haven't really tried to find a pattern of why/when it happens but what I usually do is leave the editor open for days, putting the computer to sleep and wake up after long or short time, and sometimes leaving npm start running for a react project.

Came here after seeing the tsserver process was using ~880MB; after writing this, went to take a screenshot and the process was there no more and VS Code went back to using ~287MB overall. Will try @sheetalkamat 's suggestion to log the tsserver and see what's up.

jadbox commented 5 years ago

tsserver.js is using 1.2 gigs of memory on my small-ish front-end project. I'm not sure how to create a reproducible setup for this. If needed, I could give a developer access to my project for testing.

19-07-11-09-31

OS: Linux Fedora 30 64x

jadbox commented 5 years ago

Possibly related issue: https://github.com/Microsoft/TypeScript/issues/30981

sheetalkamat commented 5 years ago

@jadbox your project along with tsserver log as per https://github.com/microsoft/TypeScript/issues/30034#issuecomment-493161120 would be helpful to investigate. Thanks.

vkaracic commented 5 years ago

Same issue with me: Screenshot from 2019-09-02 16-51-09

abriginets commented 5 years ago

Same issue here. Only 7 tabs of code opened.

image

OS: Windows 10 x64, build 1903. VS Code: 1.38.1 TypeScript: 3.6.3

mmahdigh commented 5 years ago

Same here. tsserver

Version: Code 1.39.1 (88f15d17dca836346e787762685a40bb5cce75a8, 2019-10-10T23:31:28.683Z) OS Version: Windows_NT x64 10.0.17134 CPUs: Intel(R) Core(TM) i7-4702MQ CPU @ 2.20GHz (8 x 2195) Memory (System): 5.76GB (0.82GB free) VM: 40%

sheetalkamat commented 5 years ago

Please share logs with typescript nightly for us to be able to investigate this. Screen shots though showing that you are facing the issue are not helpful for investigation at all.

You can upload logs by following these steps using typescript nightly drop.:

  1. Set "typescript.tsserver.log": "verbose"
  2. Restart vscode or vscode insiders
  3. Reproduce the problem
  4. In vscode or vscode insiders, run the TypeScript: Open TS Server log command
  5. This should open a large file called tsserver.log. Please share this file. Additionally you can also share file ti.log created next to it.
nhducseuit commented 4 years ago

tsserver.log ti-9572.log

Additionally, the 'Process Explorer' shows that tsserver used 3xxx mb memory

nhducseuit commented 4 years ago

Anybody ?

harveyconnor commented 4 years ago

having the same issue, VSCode eventually becomes unusable after developing for extended hours.

PabloHernanVila commented 4 years ago

Same issue here. Is there any update?

isostarec commented 4 years ago

Same issue here as well.

mheavenor commented 4 years ago

Looks like this may be a duplicate of this issue and will be solved with VS Code 1.43

meotimdihia commented 4 years ago

Vscode Insider 1.43 is still using 450MB+ for me.

kmvan commented 4 years ago

image

Same with me.

Watching file.

rxmoein commented 4 years ago

Same here. ts-server uses all of my 24GB ram and my operating system does not work. On PopOS Linux

SarkarKurdish commented 4 years ago

Same here Manjaro Linux it's unusable

mjbvz commented 3 years ago

Closing as we need specific repos to investigate performance issues

If you believe TSServer is using too much memory when using TS 4.1.5+, please open a new issue. Include as much information about your project as possible (ideally just like to the source code so we can reproduce this ourselves)

cristianjuarezz commented 1 year ago

This is still an issue in 2023, my IDE is not Visual Studio Code, but still reproduceable by leaving a node server running for a while. Sounds like a typical memory leak.

image image

Also I noticed: The memory only gets freed once I kill the IDE or terminal in which i had the server, and not when i kill the server with Ctrl + C

alaric8 commented 7 months ago

I have the same problem. Is there any way to solve it

IOLOII commented 5 months ago

2024.5.4 same problem again!

image

Although it is only more than 500 now, it is the size after I forced the shutdown. When I was developing the project, the memory occupied very frequently, so I had to open the process manager and close it.

jilherme commented 5 months ago

I'm having 500MB+ mem usage too

image

mjbvz commented 5 months ago

Please open new issues instead of posting on old closed ones

Also depending on what's in your project, 500mb may be expected