neoclide / coc-tsserver

Tsserver extension for coc.nvim that provide rich features like VSCode for javascript & typescript
MIT License
1.05k stars 68 forks source link

Large delays after updateOpen #442

Closed ssadler closed 8 months ago

ssadler commented 8 months ago

Hello,

I am having an issue where after changing a file, there is a large delay before I can see type information, or commands like go to definition work.

I have looked at the server logs, which show that updateOpen is taking a long time to return:

[Trace - 10:52:41.250] <semantic> Async response received: requestCompleted (3). Request took 14625 ms

The project is not huge, however, there are a few files with some complex ish types, and I did notice that some things became slower over time when introducing them.

What I don't have is a reliable way to see what types are causing the slowdown (removing import statements is hit and miss).

I'm also not sure that the slowdown is neccesary, in the sense that the code imports causing the slowdown could be cached.

Appreciate any help!

EDIT

Typescript 5.2.2 coc-tsserver 2.1.4

fannheyward commented 8 months ago

Is it slow in VS Code with the same project? The log shows tsserver was slow to respond.

ssadler commented 8 months ago

Havn't tried VS Code.

I seem to have found something though, using the recomended way to analyze performance hotspots:

$ npx tsc -p ./tsconfig.json --generateTrace tmpdir
$ npx analyze-trace tmpdir

So this is good news, been suffering with it for a while :slightly_smiling_face:

Will update and close soon

ssadler commented 8 months ago

Ok, got it sorted!

analyze-trace (@typescript/analyze-trace) reported the location of the performance hotspot. It was an SQL query using zapatos library, which was joining many tables. The issue was a large union type, it seems that there is some exponential complexity with union types. Refactoring it into a different module was not enough, I had to simplify the type (using Pick / Extract). Then it was fast again :slightly_smiling_face:. Hope this helps someone!