-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
tsserver and intellisense hang indefinitely on "loading intellisense status" and "loading..." when using assertion function and complex conditional type #51188
Comments
This seems to bisect to #49119. |
Stumbled across this one and took a quick look. The core issue is that the types in the repo are very expensive to compute, as is evident by the painful slowness of intellisense in the example. For example, checking the That said, we obviously shouldn't hang the language service and I'm not sure why that happens. The example compiles with |
Very odd that we hang in 4.8+ when those versions have the fewer instantiations; I would have assumed the opposite. |
Thanks for taking a look! I had a suspicion complexity was a problem after some other small issues with the types coming from the unist-util-visit package. For example, sometimes TS would give me "Type instantiation is excessively deep and possibly infinite" seemingly at random, then I'd restart the language server, and it would return the expected type. cc unified team: @wooorm |
That error is caused by our type instantiation governor when a single source element gives rise to >5M type instantiations. Any code that triggers this is definitely highly suspect. It looks like you were barely managing to squeeze under the limit in 4.7, so I would strongly recommend simplifying the types. In particular, the |
A TS wizard can probably improve |
I've been looking at this one, and if you uncomment just the second commented-out snippet in the linked example repo, It seems like this code is generating huge unions of huge intersections of huge unions of... and so on, and post-#49119 we can't handle it anymore; it spends all its time traversing these in relation checking and doing so turns into a huge combinatorial explosion trying to see if two of these huge types are related. |
So, just for reference, with TS 4.7, the example in my previous comment (the repro with the second block uncommented) takes ~2.18s to compile. One thing I noticed while investigating this is that the intersections produced by the code here are big, but appear to be repetitive and only differ in ordering. In #52891 I am playing around with sorting intersections. Just sorting the intersections themselves (nothing else) allows the example to compile in about 40 seconds, which is still Not Good ™️ but better than OOMing.
I'm going to try and finalize this change, e.g. add origin types to intersections to fix the display issues, but given the nature of this change, it's not likely that this can go into TS 5.0 given we're nearly at RC. |
Ugh.... nevermind, I screwed up; I had commented out the slow code in my example so I was testing the repro without modification! Very embarrassing. There's still a benefit, which is still good compared to OOMing, but, not what I was hoping. Looking for more now. |
That being said... it's still 40% for the non-bad case, which is promising in and of itself. |
My q above still stands btw: if anyone knows of a better way to do this (#51188 (comment)), I'd gladly use that. |
Unfortunately, I completely forgot that intersection ordering determines overload order, and therefore we can't sort intersections at all, so I'll have to go back to the drawing board on this. |
I was looking at this again and was surprised to find that main no longer OOMs. It turns out that #53012 (which was backported to TS 5.0 just in time for the full release) stops the OOM on this code example. I can now compile the example in ~12s, which is still a lot slower than TS 4.7's ~2s, but at least it completes! |
Bug Report
🔎 Search Terms
tsserver typescript langauge server loading intellisense status indefinite error forever asserts assertion function vscode conditional type
🕗 Version & Regression Information
4.7.4
and4.8.0-beta
and happens in all versions up to4.9.0-dev.20221015
⏯ Playground Link
Unfortunately, painstakingly copy-pasting all the types from the various packages into the playground doesn't allow me to reproduce the issue. So instead, I've created a minimal example repository that demonstrates the issue: https://github.com/Xunnamius/mre-typescript-issue-51188
💻 Code
🙁 Actual behavior
Tsserver and intellisense in vscode (latest version) hang when using a TypeScript version
>=4.8.0-beta
. See video example below.🙂 Expected behavior
Tsserver/intellisense does not hang in latest versions of vscode and TypeScript.
Untitled.mp4
The text was updated successfully, but these errors were encountered: