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

Typescript process is consuming much memory and preventing suggestions at editor #58820

Open
devhik0 opened this issue Jun 10, 2024 · 20 comments
Labels
Domain: Performance Reports of unusually slow behavior Needs Investigation This issue needs a team member to investigate its status. Needs More Info The issue still hasn't been fully clarified

Comments

@devhik0
Copy link

devhik0 commented Jun 10, 2024

πŸ”Ž Search Terms

  • slow
  • memory usage
  • typescript intellisense is working so slow at vscode

πŸ•— Version & Regression Information

  • This is a crash
  • This changed between versions 5.4 and 5.5

⏯ Playground Link

No response

πŸ’» Code

// Your code here

πŸ™ Actual behavior

When i make a mistake in my code, my ram usage is increasing much and intellisense is not showing errors/warnings in expected time period like 1-2 sec. Sometimes its hanging and i am waiting for minutes to see its response.
Not sure but i think that error below is causing that performance issues.

ERR <semantic> TypeScript Server Error (5.5.0-dev.20240603)
BADCLIENT: Bad error code, 7006 not found in range 399..403 (found: ); could have caused this error:
Debug Failure. Invalid cast. The supplied value [object Object] did not pass the test 'isParameter'.
Error: BADCLIENT: Bad error code, 7006 not found in range 399..403 (found: ); could have caused this error:
Debug Failure. Invalid cast. The supplied value [object Object] did not pass the test 'isParameter'.
    at cast (c:\Users\aydin\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\typescript.js:3478:16)
    at doChange33 (c:\Users\aydin\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\typescript.js:159733:23)
    at c:\Users\aydin\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\typescript.js:159617:21
    at _ChangeTracker.with (c:\Users\aydin\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\typescript.js:174292:5)
    at Object.getCodeActions (c:\Users\aydin\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\typescript.js:159616:62)
    at c:\Users\aydin\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\typescript.js:151199:46
    at flatMap (c:\Users\aydin\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\typescript.js:2634:17)
    at Object.getFixes (c:\Users\aydin\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\typescript.js:151199:10)
    at c:\Users\aydin\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\typescript.js:149479:33
    at flatMap (c:\Users\aydin\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\typescript.js:2634:17)
    at Object.getCodeFixesAtPosition (c:\Users\aydin\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\typescript.js:149477:12)
    at IOSession.getCodeFixes (c:\Users\aydin\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\typescript.js:191171:50)
    at getCodeFixes (c:\Users\aydin\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\typescript.js:189255:43)
    at c:\Users\aydin\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\typescript.js:191478:69
    at IOSession.executeWithRequestId (c:\Users\aydin\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\typescript.js:191470:14)
    at IOSession.executeCommand (c:\Users\aydin\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\typescript.js:191478:29)
    at IOSession.onMessage (c:\Users\aydin\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\typescript.js:191520:51)
    at Interface.<anonymous> (c:\Users\aydin\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\tsserver.js:499:14)
    at Interface.emit (node:events:514:28)
    at [_onLine] [as _onLine] (node:internal/readline/interface:416:12)
    at [_normalWrite] [as _normalWrite] (node:internal/readline/interface:610:22)
    at Socket.ondata (node:internal/readline/interface:243:23)
    at Socket.emit (node:events:514:28)
    at addChunk (node:internal/streams/readable:545:12)
    at readableAddChunkPushByteMode (node:internal/streams/readable:495:3)
    at Readable.push (node:internal/streams/readable:375:5)
    at Pipe.onStreamRead (node:internal/stream_base_commons:190:23): Error: <semantic> TypeScript Server Error (5.5.0-dev.20240603)
BADCLIENT: Bad error code, 7006 not found in range 399..403 (found: ); could have caused this error:
Debug Failure. Invalid cast. The supplied value [object Object] did not pass the test 'isParameter'.
Error: BADCLIENT: Bad error code, 7006 not found in range 399..403 (found: ); could have caused this error:
Debug Failure. Invalid cast. The supplied value [object Object] did not pass the test 'isParameter'.
    at cast (c:\Users\aydin\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\typescript.js:3478:16)
    at doChange33 (c:\Users\aydin\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\typescript.js:159733:23)
    at c:\Users\aydin\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\typescript.js:159617:21
    at _ChangeTracker.with (c:\Users\aydin\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\typescript.js:174292:5)
    at Object.getCodeActions (c:\Users\aydin\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\typescript.js:159616:62)
    at c:\Users\aydin\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\typescript.js:151199:46
    at flatMap (c:\Users\aydin\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\typescript.js:2634:17)
    at Object.getFixes (c:\Users\aydin\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\typescript.js:151199:10)
    at c:\Users\aydin\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\typescript.js:149479:33
    at flatMap (c:\Users\aydin\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\typescript.js:2634:17)
    at Object.getCodeFixesAtPosition (c:\Users\aydin\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\typescript.js:149477:12)
    at IOSession.getCodeFixes (c:\Users\aydin\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\typescript.js:191171:50)
    at getCodeFixes (c:\Users\aydin\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\typescript.js:189255:43)
    at c:\Users\aydin\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\typescript.js:191478:69
    at IOSession.executeWithRequestId (c:\Users\aydin\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\typescript.js:191470:14)
    at IOSession.executeCommand (c:\Users\aydin\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\typescript.js:191478:29)
    at IOSession.onMessage (c:\Users\aydin\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\typescript.js:191520:51)
    at Interface.<anonymous> (c:\Users\aydin\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\tsserver.js:499:14)
    at Interface.emit (node:events:514:28)
    at [_onLine] [as _onLine] (node:internal/readline/interface:416:12)
    at [_normalWrite] [as _normalWrite] (node:internal/readline/interface:610:22)
    at Socket.ondata (node:internal/readline/interface:243:23)
    at Socket.emit (node:events:514:28)
    at addChunk (node:internal/streams/readable:545:12)
    at readableAddChunkPushByteMode (node:internal/streams/readable:495:3)
    at Readable.push (node:internal/streams/readable:375:5)
    at Pipe.onStreamRead (node:internal/stream_base_commons:190:23)
	at n.create (c:\Users\aydin\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\typescript-language-features\dist\extension.js:1:473136)
	at v.dispatchResponse (c:\Users\aydin\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\typescript-language-features\dist\extension.js:1:467106)
	at v.dispatchMessage (c:\Users\aydin\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\typescript-language-features\dist\extension.js:1:465950)
	at n.value (c:\Users\aydin\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\typescript-language-features\dist\extension.js:1:465443)
	at s.B (c:\Users\aydin\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:83:737)
	at s.fire (c:\Users\aydin\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:83:954)
	at y.onLengthData (c:\Users\aydin\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\typescript-language-features\dist\extension.js:1:476865)
	at Socket.<anonymous> (c:\Users\aydin\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\typescript-language-features\dist\extension.js:1:476512)
	at Socket.emit (node:events:514:28)
	at addChunk (node:internal/streams/readable:376:12)
	at readableAddChunk (node:internal/streams/readable:349:9)
	at Readable.push (node:internal/streams/readable:286:10)
	at Pipe.onStreamRead (node:internal/stream_base_commons:190:23)

πŸ™‚ Expected behavior

At mistakes, seeing errors/warnings in short period.

Additional information about the issue

When i check logs and traces i am seeing a lot different packages are downloading while the error-checking continues. Like this:

{"pid":1,"tid":1,"ph":"X","cat":"check","ts":1003639605.0000191,"name":"checkExpression","dur":467.7000045776367,"args":{"kind":80,"pos":432,"end":438,"path":"c:/users/aydin/web/app/crm-saas/client-app/node_modules/@radix-ui/react-primitive/dist/index.d.mts"}},
{"pid":1,"tid":1,"ph":"X","cat":"check","ts":1003639364.4000292,"name":"checkExpression","dur":2160.399913787842,"args":{"kind":80,"pos":201,"end":211,"path":"c:/users/aydin/web/app/crm-saas/client-app/node_modules/@radix-ui/react-dismissable-layer/dist/index.d.mts"}},
{"pid":1,"tid":1,"ph":"X","cat":"check","ts":1003639358.899951,"name":"checkExpression","dur":2578.8999795913696,"args":{"kind":166,"pos":201,"end":215,"path":"c:/users/aydin/web/app/crm-saas/client-app/node_modules/@radix-ui/react-dismissable-layer/dist/index.d.mts"}},
{"pid":1,"tid":1,"ph":"I","cat":"session","ts":1004819072.8000402,"name":"cancellationThrown","s":"g","args":{"kind":"CancellationTokenObject"}},
{"pid":1,"tid":1,"ph":"X","cat":"check","ts":1003631394.6999311,"name":"checkExpression","dur":1187831.300020218,"args":{"kind":213,"pos":991,"end":2353,"path":"c:/users/aydin/web/app/crm-saas/client-app/components/ui/dialog.tsx"}},
{"pid":1,"tid":1,"ph":"X","cat":"check","ts":1003630949.3999481,"name":"checkExpression","dur":1188276.6000032425,"args":{"kind":80,"pos":563,"end":576,"path":"c:/users/aydin/web/app/crm-saas/client-app/app/calendar/add-event-form.tsx"}},

Trace-20240610T183642.json

Also at this process: C:\Program Files\nodejs\node.exe" --max-old-space-size=12000 "c:\Users\aydin\AppData\Local\Programs\Microsoft VS Code Insiders\resources\app\extensions\node_modules\typescript\lib\tsserver.js" --useInferredProjectPerProjectRoot --enableTelemetry --cancellationPipeName C:\Users\aydin\AppData\Local\Temp\vscode-typescript\465f576e122de7f00782\tscancellation-f24a4ea23cca8e2de700.tmp* --traceDirectory "\"c:\Users\aydin\AppData\Roaming\Code - Insiders\logs\20240610T180039\window1\exthost\vscode.typescript-language-features\tsserver-log-7zZxSQ\"" --locale en --noGetErrOnBackgroundUpdate --canUseWatchEvents --validateDefaultNpmLocation 504.904 K there is around 500mb memory usage, even i give 12GB to it.

I could say i cant code because of these kind of problems.

@DanielRosenwasser
Copy link
Member

Hey there, sorry about this - this seems like an awful experience.

Is this specifically a problem with only editing? Are you seeing an increase in build time as well? I don't suppose you've been able to run the results of your trace via https://github.com/microsoft/typescript-analyze-trace, have you? That will make things easier to diagnose in terms of performance, and will make it easier to understand what is slower now compared to 5.4.

There is also every-ts to help figure out which commit of TypeScript introduced a regression. If you can run that to help diagnose the issue, it would be extremely helpful.

@DanielRosenwasser DanielRosenwasser added Needs More Info The issue still hasn't been fully clarified Needs Investigation This issue needs a team member to investigate its status. Domain: Performance Reports of unusually slow behavior labels Jun 11, 2024
@devhik0
Copy link
Author

devhik0 commented Jun 11, 2024

Well actually I am not using TSC to build my project cuz it's a next.js project. As I know it's using swc to build but I don't have problems at build.

Only happens at editing and typing. I am also using vscode if matters. I generated that trace i attached via vscode's tsserver traces.

I checked same thing at another project and another editor and also at another OS :D , only difference was at Neovim with (coc.nvim) TS server LSP. coc-ts

Also at version check i tried both vscode's TS version and my project's version (5.5, 5.4.5) both were same.

What's happening basically:

I am making a mistake at code then I am waiting for diagnostics, meanwhile my fans are buzzing, my CPU and memory usage increasing around 80%,
the process continuing and it's not showing anything as solution at intellisense.
Even when I correct my mistake, returning back to normal state takes 5-6 sec and my fans and usage becomes same again.

I checked performance profile at vscode, i saw a similar graphic describes that problem.

Here i am sharing what i see while coding: :(

diag
mem-diag

Here is for neovim with coc-tsserver
"C:\Program Files\nodejs\node.EXE" --max-old-space-size=11196 C:\Users\aydin\AppData\Local\coc\extensions\node_modules\coc-tsserver\node_modules\typescript\lib\tsserver.js --useInferredProjectPerProjectRoot --cancellationPipeName C:\Users\aydin\AppData\Local\Temp\coc-tsserver\3956c3a1a44238ae64fa\tscancellation-95086c00069497dac2c0.tmp* --locale en --noGetErrOnBackgroundUpdate --validateDefaultNpmLocation --useNodeIpc

vim-diag

I am okay for high resource consumption for these kind of things, however i dont know why its not ending and showing.

@devhik0
Copy link
Author

devhik0 commented Jun 17, 2024

Anything ?

@stackyism
Copy link

@devhik0 Is it possible that this might be related to #58011 which will be fixed in 5.5.0 through #58398 PR ?

@devhik0
Copy link
Author

devhik0 commented Jun 18, 2024

I used 5.5 to write that logs though, still today it's hanging for long minutes like 5min to show a diagnostic

@stackyism
Copy link

@devhik0 Oh okay. My bad then. It seems unrelated. Apologies for the inconvenience.

@devhik0
Copy link
Author

devhik0 commented Jun 18, 2024

No problem @stackyism , i don't think this problem has a solution tbh

@devhik0
Copy link
Author

devhik0 commented Jul 1, 2024

Anything?

@stackyism
Copy link

stackyism commented Jul 1, 2024

Anything?

Have you tried using analyze-trace of extendedDiagnostics as mentioned here ?

It actually really helped me find the Hot spots and lead me to exact files which were causing excessive computation in generics.

Hot Spots
β”œβ”€ Check file [/Volumes/stuff/types.ts]

Note: try and give your extendedDiagnostics command a lot of memory in advance for it to not break.

@devhik0
Copy link
Author

devhik0 commented Jul 1, 2024

I am not using TSC @stackyism

@stackyism
Copy link

stackyism commented Jul 1, 2024

I am not using TSC @stackyism

That's completely fine, we don't use it as well, we use nx to run our builds and it does type checking based on plugins.
But this tsc usages is just to help with diagnosis and not replace the actual working solution whatever you maybe using.

Does this make sense or am I misunderstanding by what you mean that you don't use TSC ? πŸ€”

these commands will just need corresponding tsconfig files used to run typescript checking.

Also, just a side note, I meant --generateTrace flag for analyze-trace and not extendedDiagnostics.

I used following command to output the trace folder
yarn tsc -p myapp/tsconfig.app.json --generateTrace myapp/trace-5.4.5-no-changes
And
yarn analyze-trace myapp/trace-5.4.5-no-changes > diagnostics-no-change.txt

@devhik0
Copy link
Author

devhik0 commented Jul 1, 2024

My commands are starting with next and its using swc. But my problem is with VSCode's typescript server which I can't use any commands to run it @stackyism

@stackyism
Copy link

stackyism commented Jul 1, 2024

My commands are starting with next and its using swc. But my problem is with VSCode's typescript server which I can't use any commands to run it

I understand that. As per my understanding, nextJS app should have a tsconfig.json file in your root folder and there must be a typescript package with some version in your package.json ?
If you can confirm if both of the above are true, then, you can use your local installed typescript in node_modules to run the above commands. tsc

Would you need help with that ?

@devhik0
Copy link
Author

devhik0 commented Jul 1, 2024

:) Thanks for your help but I think I couldn't explain myself much. Think you have vscode, you have some .TS files and editing those. While editing it's taking minutes to show diagnostics. I don't want compile, i am looking for diagnostics

When i make a mistake in my code, my ram usage is increasing much and intellisense is not showing errors/warnings in expected time period like 1-2 sec. Sometimes its hanging and i am waiting for minutes to see its response.

@devhik0
Copy link
Author

devhik0 commented Jul 1, 2024

Well actually I am not using TSC to build my project cuz it's a next.js project. As I know it's using swc to build but I don't have problems at build.

Only happens at editing and typing. I am also using vscode if matters. I generated that trace i attached via vscode's tsserver traces.

I checked same thing at another project and another editor and also at another OS :D , only difference was at Neovim with (coc.nvim) TS server LSP. coc-ts

Also at version check i tried both vscode's TS version and my project's version (5.5, 5.4.5) both were same.

What's happening basically:

I am making a mistake at code then I am waiting for diagnostics, meanwhile my fans are buzzing, my CPU and memory usage increasing around 80%,
the process continuing and it's not showing anything as solution at intellisense.
Even when I correct my mistake, returning back to normal state takes 5-6 sec and my fans and usage becomes same again.

I checked performance profile at vscode, i saw a similar graphic describes that problem.

Here i am sharing what i see while coding: :(

diag
mem-diag

Here is for neovim with coc-tsserver
"C:\Program Files\nodejs\node.EXE" --max-old-space-size=11196 C:\Users\aydin\AppData\Local\coc\extensions\node_modules\coc-tsserver\node_modules\typescript\lib\tsserver.js --useInferredProjectPerProjectRoot --cancellationPipeName C:\Users\aydin\AppData\Local\Temp\coc-tsserver\3956c3a1a44238ae64fa\tscancellation-95086c00069497dac2c0.tmp* --locale en --noGetErrOnBackgroundUpdate --validateDefaultNpmLocation --useNodeIpc

vim-diag

I am okay for high resource consumption for these kind of things, however i dont know why its not ending and showing.

Also check this @stackyism

@stackyism
Copy link

stackyism commented Jul 1, 2024

Okay. So, it looks like I understand why this might be confusing.

As per the above messages, you're facing issues with Visual code not providing proper typescript intellisense due to huge computation time. Intellisense basically keeps checking your code for typescript error through ts-server which keeps compiling your code and gives you errors or recommendations.

Now, I'll just try to iterate how I wanted to help.

  1. ts server in vscode runs compilation on your code using tsconfig.json. That's what gives you the errors when you make changes in vscode.
  2. The reason for taking too much time or not giving result back to you when you make changes could be due to high memory usage by ts-server in compilation.
  3. To find out where could be the high amount of computation is happening or where's the memory leak, you have to compiler your TS files manually using a diagnostics script. This will not replace your workflow of making changes in vscode and getting intellisense suggestions, this is just a way to find out the root cause of the problem. Problem could be 1 or multiple files, perhaps maybe the file which you're editing.
  4. To find out that potential memory leak, you've to use tools available from typescript side (this doesn't involve using vscode), just requires running some commands in the root of your app. Those commands are the one I mentioned above tsc --generateTrace & analyze-trace.
  5. These will give you output files which will consist the data of what happens during typescript compilation which happens through ts-server on your vscode.
  6. Once you have those files and analysis, then you just need fix those files and forget about any builds or these commands. Your workflow will continue as normal in vs code.

Does this make sense or maybe I've completely misunderstood the problem here ?
But this is the best I could try to help.

@devhik0
Copy link
Author

devhik0 commented Jul 1, 2024

Do you have discord, i want to show you what I want actually @stackyism

@stackyism
Copy link

Do you have discord, i want to show you what I want actually @stackyism

Yes. I've joined typescript discord server and have user name saagar.takhi8606.

@devhik0
Copy link
Author

devhik0 commented Jul 1, 2024

I sent request on discord, please accept that @stackyism

@devhik0
Copy link
Author

devhik0 commented Jul 1, 2024

I wish to discuss this with Mr.Hejlsberg, wondering his ideas always :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Domain: Performance Reports of unusually slow behavior Needs Investigation This issue needs a team member to investigate its status. Needs More Info The issue still hasn't been fully clarified
Projects
None yet
Development

No branches or pull requests

3 participants