-
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
Massive slowdown in compiling complicated union types #5849
Comments
@Arnavion can you give a try to typescript@next. Seems that this issue is already fixed in master. I can confirm that it takes 17.50 s on my machine to compile your sample using release-1.7, however on master it takes only 0.71 s |
Yes, looks like it. The original code also takes ~2s with next, same as 1.6. |
Can the fix be backported to 1.7 or do I skip it and wait for 1.8? |
depends on the fix. @vladima do you know what is going on? |
yes: #5738. If source and target types are unions or intersections then removing matching constituents from source and target sides significantly reduces amount of types that participate in type inference. I think it should be safe to backport this fix to 1.7 |
Yes, cherry-picking that PR onto 1.7 fixes the issue (and introduces #5861 but that's a minor annoyance in comparison). |
@Arnavion is there a chance you can move to |
If you're asking because you don't want to backport it, that's fine. I have no problem staying with 1.6 until 1.8 is released. :) |
I am asking to figure out the logistics, porting it and publishing an npm is easy, but we will need to publish a VS 2012, VS 2015, and sublime text plugin updates and that all adds up. |
I'm trying to understand why this got slower from 1.6 to 1.7? Vlad, did you look into that? I understand why the new union/intersection reduction in 1.8 makes it faster, but I'd like to know why it got slower in the first place. |
Ok, I now understand why it got slower. When inferring types, if the source and target are both non-generic object types we don't descend into the types because it we know it won't produce inferences. However, in 1.7 all classes are generic because of the implied |
yes, this got slower in the 9438a4b |
Ok, I have a fix. I will putting up a PR shortly. |
I would recommend not back-porting the union/intersection type reduction, but instead back-porting the #5920 fix I just put up. |
@Arnavion can you do us a big favor and give branch release-1.7 a quick test? |
Everything seems fine. Thanks! |
thanks @Arnavion! |
This is the same code as what originally prompted #2997
While it isn't crashing because of infinite loops any more, it has become very slow with 1.7. If I pause it in the debugger I see the following stack repeating many times.
Reduced test case:
Compile with
tsc foo.ts
on node 4.2.2 x64 on Windows 7.This takes ~18s on my machine. If I remove
Module
from the union type at (1), it drops to ~12s. RemovingModule
at (2) drops it to ~6s. And so on.The original code is at https://github.com/Arnavion/libjass/blob/82f3706/build/typescript/ast.ts which has a much more complicated forest of types. It's been compiling for 5 minutes now, whereas it took ~2s with 1.6
The text was updated successfully, but these errors were encountered: