microsoft / TypeScript

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

Memory leak in tsserver #42767

Closed deepak1556 closed 1 month ago

deepak1556 commented 3 years ago

Steps to Reproduce:

  1. Launch with --disable-extensions
  2. Open any js or ts file
  3. wait for few seconds and close
  4. Repeat step 2) and 3) for a few times
  5. See memory usage of tsserver process keeps increasing easily to > 1GB
CPU %   Mem MB     PID  Process
    1       98   20845  code-insiders main
    0      164   20848     gpu-process
    0       33   20850     utility
    0      229   20851     window (console.ts)
    2       66   20853       extensionHost
    0       66   20958         electron_node tsserver.js 
    0     1704   20959         electron_node tsserver.js 
    0       33   20969           electron_node typingsInstaller.js typesMap.js 
    0       33   21141         /Applications/Visual Studio Code - Insiders.app/Contents/Frameworks/Code - Insiders Helper (Renderer).app/Contents/MacOS/Code - Insiders Helper (Renderer) /Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/extensions/json-language-features/server/dist/node/jsonServerMain --node-ipc --clientProcessId=20853
    0       98   23916         /Applications/Visual Studio Code - Insiders.app/Contents/Frameworks/Code - Insiders Helper (Renderer).app/Contents/MacOS/Code - Insiders Helper (Renderer) /Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/extensions/html-language-features/server/dist/node/htmlServerMain --node-ipc --clientProcessId=20853
    0       33   20854       watcherService
    0       66   20871     shared-process

CPU profile of TSServer process:

profile.zip

Heap Snapshot of TSServer process:

https://microsoft-my.sharepoint.com/:f:/p/demohan/EgdUquRTfAZGisNrUmAI1JUBIVLGe1gQS4muGTByc7Thgw?e=2gQP8O

mjbvz commented 3 years ago

I wasn't able to reproduce this in my testing on MacOS with a single file. Maybe someone on the TS team would be able to learn more from the logs though

@deepak1556 Can you also try collecting the TS Server log when this happens:

  1. Set "typescript.tsserver.log": "verbose",
  2. Restart VS Code and reproduce the problem
  3. In VS Code, run the TypeScript: Open TS Server log command
  4. This should open a large log file called tsserver.log
deepak1556 commented 3 years ago

Attaching the logs from above,

Archive.zip

mjbvz commented 3 years ago

Thanks @deepak1556! This was for a new JS file src/bootstrap-node.js in the VS Code codebase, correct?

Someone on the TS team will have to look at the logs. It does look like a lot of d.ts files are being loaded but I'm not sure if this is unexpected or not

deepak1556 commented 3 years ago

This was for a new JS file src/bootstrap-node.js in the VS Code codebase, correct?

Yup I was just viewing files in the VS Code codebase for someother issue when I noticed this memory consumption.

sheetalkamat commented 3 years ago

I havent seen the issue with memory when i tried to follow the steps you have followed... it seems to be doing well on memory and its in ~650M so i dont see any leak as such .. This should be expected given the number of files that are kept around (vscode main project + inferred project). I dont see anything in the logs that indicates somehting going wrong either.. i followed all the steps in the log locally and still so no leak. Not sure if there is anything actionable here at this point.