Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slow Typescript problem reporting and intellisense #56142

Open
sagarpanchal opened this issue Aug 25, 2023 · 7 comments
Open

Slow Typescript problem reporting and intellisense #56142

sagarpanchal opened this issue Aug 25, 2023 · 7 comments
Labels
Needs More Info The issue still hasn't been fully clarified

Comments

@sagarpanchal
Copy link

Type: Performance Issue

After some time typescript features slows down

VS Code version: Code 1.81.1 (Universal) (6c3e3dba23e8fadc360aed75ce363ba185c49794, 2023-08-09T22:20:33.924Z)
OS version: Darwin arm64 22.5.0
Modes:

System Info
Item Value
CPUs Apple M2 (8 x 24)
GPU Status 2d_canvas: enabled
canvas_oop_rasterization: disabled_off
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
metal: disabled_off
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: enabled
Load (avg) 2, 2, 2
Memory (System) 16.00GB (0.14GB free)
Process Argv
Screen Reader no
VM 0%
Process Info
CPU %	Mem MB	   PID	Process
   18	   197	   833	code main
    0	    98	   835	   gpu-process
    0	    33	   838	   utility-network-service
    2	   672	   839	window [1] (CodeAnalyzer.ts — ts-analyzer)
   43	    98	   870	shared-process
    0	     0	  5565	     /bin/ps -ax -o pid=,ppid=,pcpu=,pmem=,command=
    0	    49	   871	fileWatcher [1]
    0	   705	   896	extensionHost [1]
    0	   262	   914	     electron-nodejs (/Applications/Visual Studio Code.app/Contents/Frameworks/Code Helper (Plugin).app/Contents/MacOS/Code Helper (Plugin) --ms-enable-electron-run-as-node /Users/sagarpanchal/.vscode/extensions/dbaeumer.vscode-eslint-2.4.2/server/out/eslintServer.js --node-ipc --clientProcessId=896)
    0	   115	   915	     electron-nodejs (/Applications/Visual Studio Code.app/Contents/Frameworks/Code Helper (Plugin).app/Contents/MacOS/Code Helper (Plugin) --ms-enable-electron-run-as-node /Users/sagarpanchal/.vscode/extensions/streetsidesoftware.code-spell-checker-2.20.5/packages/_server/dist/main.js --node-ipc --clientProcessId=896)
    0	    49	   916	     electron-nodejs (/Applications/Visual Studio Code.app/Contents/Frameworks/Code Helper (Plugin).app/Contents/MacOS/Code Helper (Plugin) --ms-enable-electron-run-as-node /Users/sagarpanchal/.vscode/extensions/stylelint.vscode-stylelint-1.2.4/dist/start-server.js --stdio --clientProcessId=896)
    0	    82	   950	     electron-nodejs (/Applications/Visual Studio Code.app/Contents/Frameworks/Code Helper (Plugin).app/Contents/MacOS/Code Helper (Plugin) --ms-enable-electron-run-as-node /Applications/Visual Studio Code.app/Contents/Resources/app/extensions/json-language-features/server/dist/node/jsonServerMain --node-ipc --clientProcessId=896)
    0	   115	  4485	     electron-nodejs (/Applications/Visual Studio Code.app/Contents/Frameworks/Code Helper (Plugin).app/Contents/MacOS/Code Helper (Plugin) --ms-enable-electron-run-as-node --max-old-space-size=4096 /Users/sagarpanchal/Documents/Projects/ts-analyzer/node_modules/typescript/lib/tsserver.js --serverMode partialSemantic --useInferredProjectPerProjectRoot --disableAutomaticTypingAcquisition --cancellationPipeName /var/folders/bn/67f8lxf55wbf6fv2c1ymr3w80000gn/T/vscode-typescript501/acdc844d442fdf314ff9/tscancellation-8b39db15f9efe61b4a56.tmp* --locale en --noGetErrOnBackgroundUpdate --validateDefaultNpmLocation --useNodeIpc)
    0	   262	  4486	     electron-nodejs (/Applications/Visual Studio Code.app/Contents/Frameworks/Code Helper (Plugin).app/Contents/MacOS/Code Helper (Plugin) --ms-enable-electron-run-as-node --max-old-space-size=4096 /Users/sagarpanchal/Documents/Projects/ts-analyzer/node_modules/typescript/lib/tsserver.js --useInferredProjectPerProjectRoot --enableTelemetry --cancellationPipeName /var/folders/bn/67f8lxf55wbf6fv2c1ymr3w80000gn/T/vscode-typescript501/acdc844d442fdf314ff9/tscancellation-0dc40f534e587793d165.tmp* --locale en --noGetErrOnBackgroundUpdate --validateDefaultNpmLocation --useNodeIpc)
    0	    49	  4488	       electron-nodejs (/Applications/Visual Studio Code.app/Contents/Frameworks/Code Helper (Plugin).app/Contents/MacOS/Code Helper (Plugin) --ms-enable-electron-run-as-node /Users/sagarpanchal/Documents/Projects/ts-analyzer/node_modules/typescript/lib/typingsInstaller.js --globalTypingsCacheLocation /Users/sagarpanchal/Library/Caches/typescript/5.1 --enableTelemetry --typesMapLocation /Users/sagarpanchal/Documents/Projects/ts-analyzer/node_modules/typescript/lib/typesMap.json --validateDefaultNpmLocation)
    0	    49	   972	ptyHost
    0	     0	   973	     /bin/zsh -l
    0	     0	  1054	       npm run serve
    0	     0	  1055	         /bin/sh /Users/sagarpanchal/.volta/tools/image/npm/9.8.1/bin/npm run serve
    0	    33	  1059	           npm run serve
    0	    33	  1080	             node /Users/sagarpanchal/Documents/Projects/ts-analyzer/node_modules/.bin/serve public
    0	     0	  2933	     /bin/zsh -l
    0	    98	  5563	window [2] (Issue Reporter)
Workspace Info
|  Window (CodeAnalyzer.ts — ts-analyzer)
|    Folder (ts-analyzer): 90 files
|      File types: ts(25) js(22) json(15) gitignore(3) html(2) DS_Store(1)
|                  editorconfig(1) eslintignore(1) gitattributes(1) sh(1)
|      Conf files: launch.json(1) settings.json(1) tasks.json(1)
|                  package.json(1) tsconfig.json(1)
|      Launch Configs: node;
Extensions (63)
Extension Author (truncated) Version
commit-message-editor ada 0.25.0
project-manager ale 12.7.0
chronicler arc 0.1.16
insertnumbers Asu 0.9.1
emojisense bie 0.10.0
tabulous bwi 1.2.0
bracket-viz Chr 0.0.3
postcss css 1.0.9
vscode-eslint dba 2.4.2
css-flexbox-cheatsheet dzh 3.3.3
css-initial-value dzh 0.2.6
git-cheatsheet dzh 1.4.4
rxjs-cheatsheet dzh 1.2.1
gitlens eam 14.2.1
EditorConfig Edi 0.16.4
prettier-vscode esb 10.1.0
code-runner for 0.12.0
shell-format fox 7.2.5
vscode-google-translate fun 1.4.13
gc-excelviewer Gra 4.2.58
selected-lines-count gur 1.4.0
draw hal 0.2.0
vscode-drawio hed 1.6.6
rest-client hum 0.25.1
output-colorizer IBM 0.1.2
batch-rename-extension Jan 0.0.6
search-node-modules jas 1.3.0
svg joc 1.5.3
openscad-language-support Lea 1.2.5
json-table-viewer len 0.0.5
camelcasenavigation map 1.1.5
ts-error-translator mat 0.10.0
dotenv mik 1.0.1
sort-selection-concentrically min 1.0.4
vscode-scss mrm 0.10.0
black-formatter ms- 2023.4.1
python ms- 2023.14.0
vscode-pylance ms- 2023.8.40
atom-keybindings ms- 3.3.0
cmake-tools ms- 1.15.31
cpptools ms- 1.17.4
hexeditor ms- 1.9.12
material-icon-theme PKi 4.29.0
polacode pnp 0.3.4
quicktype qui 12.0.46
sqlite-viewer qwt 0.3.13
vscode-yaml red 1.14.0
blank-line-organizer rin 0.1.5
px-to-rem sai 1.3.1
code-spell-checker str 2.20.5
vscode-stylelint sty 1.2.4
vscode-h2o tet 0.2.11
shellcheck tim 0.33.1
pdf tom 1.2.2
cmake twx 0.0.17
luna-paint Tyr 0.16.0
sort-lines Tyr 1.10.2
highlight-matching-tag vin 0.11.0
vscodeintellicode-completions Vis 1.0.22
vscode-todo-highlight way 1.0.5
change-case wma 1.0.0
CSS-sorter zas 0.2.1
material-theme zhu 3.16.0
@keyork
Copy link

keyork commented Aug 25, 2023

Perhaps you can try updating your TypeScript version to the latest release?

@sagarpanchal
Copy link
Author

@mjbvz @keyork

Switching to [email protected] seems to be solving the issue. But I need to use 5.2.2.

Switching to TS 4.9.5

  • Completions are snappy
  • Problems are reported fast.

When I switched back to TS 5.2.2

  • Completions popup keeps showing loading... and stops showing completions
    • I find myself frequently hitting CMD + SPACE, and waiting for 20-30 seconds
  • Problems take ages to update.

@sagarpanchal
Copy link
Author

This is how I am surviving right now,

Installed [email protected]

npm i -g [email protected];

Added this in settings.json

{
  ...
  // "typescript.tsdk": "~/.volta/tools/shared/typescript/lib" // I am using volta on mac
  "typescript.tsdk": "<npm_root>/typescript/lib" // Place your `npm root -g` here
}

@mjbvz
Copy link
Contributor

mjbvz commented Oct 16, 2023

@sagarpanchal Please try to share an example project which demonstrates the issue so we can investigate

@sagarpanchal
Copy link
Author

sagarpanchal commented Oct 17, 2023

@mjbvz
Unfortunately, I can not share the full code.
And I am not able to reproduce this issue after the following changes.

Since, I created this issue,

Version: 1.83.1
Commit: f1b07bd25dfad64b0167beb15359ae573aecd2cc
Date: 2023-10-10T23:57:32.750Z
Electron: 25.8.4
ElectronBuildId: 24154031
Chromium: 114.0.5735.289
Node.js: 18.15.0
V8: 11.4.183.29-electron.0
OS: Darwin arm64 23.0.0

I had a loop like this, that was taking around 3000-4000 ms, when I did analyze-trace using https://github.com/microsoft/typescript-analyze-trace

import TsMorph, { ts } from "ts-morph"

for (const syntaxKind of [
  ts.SyntaxKind.PropertyAssignment,
  ts.SyntaxKind.ShorthandPropertyAssignment,
  ts.SyntaxKind.VariableDeclaration,
  ts.SyntaxKind.FunctionDeclaration,
]) {
  // ... code
}

I have changed it to this const array, and is not taking much time anymore

import TsMorph, { ts } from "ts-morph"

for (const syntaxKind of [
  ts.SyntaxKind.PropertyAssignment,
  ts.SyntaxKind.ShorthandPropertyAssignment,
  ts.SyntaxKind.VariableDeclaration,
  ts.SyntaxKind.FunctionDeclaration,
] as const) { // <-- "as const" because SyntaxKind is a large enum
  // ... code
}

I am still not sure if it was the issue with vscode or the packages that I was using or the changes I have done after analyze-trace.

tsconfig.json

{
  "compilerOptions": {
    "allowJs": true,
    "allowSyntheticDefaultImports": true,
    "allowUnreachableCode": true,
    "declaration": true,
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "importHelpers": true,
    "isolatedModules": true,
    "lib": ["ESNext"],
    "module": "CommonJS",
    "moduleResolution": "Node",
    "outDir": "dist",
    "resolveJsonModule": true,
    "rootDir": ".",
    "skipLibCheck": true,
    "strict": true,
    "target": "ES2019",
    "useDefineForClassFields": true
  },
  "include": ["scripts/**/*", "src/**/*"]
}

package.json dependencies

{
  "dependencies": {
    "@dagrejs/graphlib": "^2.1.13",
    "@total-typescript/ts-reset": "^0.5.1",
    "eslint-plugin-jest": "^27.4.2",
    "fs-extra": "^11.1.1",
    "ignore": "^5.2.4",
    "jest": "^29.7.0",
    "jsonc-parser": "^3.2.0",
    "minimatch": "^9.0.3",
    "serve": "^14.2.1",
    "ts-jest": "^29.1.1",
    "ts-morph": "^20.0.0",
    "tslib": "^2.6.2",
    "zod": "^3.22.4"
  },
  "devDependencies": {
    "@types/fs-extra": "^11.0.2",
    "@types/jest": "^29.5.5",
    "@types/node": "^20.8.4",
    "@typescript-eslint/eslint-plugin": "^6.7.5",
    "@typescript-eslint/parser": "^6.7.5",
    "eslint": "^8.51.0",
    "eslint-config-prettier": "^9.0.0",
    "eslint-import-resolver-typescript": "^3.6.1",
    "eslint-plugin-import": "^2.28.1",
    "eslint-plugin-prettier": "^5.0.1",
    "execa": "npm:@esm2cjs/execa@^6.1.1-cjs.1",
    "husky": "^8.0.3",
    "lint-staged": "^14.0.1",
    "prettier": "^3.0.3",
    "shx": "^0.3.4",
    "ts-node": "^10.9.1",
    "type-fest": "^4.4.0",
    "typescript": "~5.2.2"
  },
}

@sagarpanchal
Copy link
Author

@mjbvz I think the issue was the way I was using the SyntaxKind enum from typescript in array

@mjbvz mjbvz transferred this issue from microsoft/vscode Oct 17, 2023
@mjbvz mjbvz removed their assignment Oct 17, 2023
@RyanCavanaugh RyanCavanaugh added the Needs More Info The issue still hasn't been fully clarified label Oct 20, 2023
@Southclaws
Copy link

I'm also running into this after moving from v4 to v5, annoyingly I need v5 for a particular library that saves a ton of time for me so I'm still weighing up the tradeoff between having essentially zero intellisense or using ts-pattern.

Fortunately, my codebase is open source so hopefully it's useful in debugging this issue: https://github.com/Southclaws/storyden

I'm not sure what I can do in the meantime though, but I used to write C so the pain is familiar at least 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs More Info The issue still hasn't been fully clarified
Projects
None yet
Development

No branches or pull requests

5 participants