Defer union and intersection type reduction #26848
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When constructing union and intersection types, we eagerly remove duplicate function types that originate in function or method declarations. This eager reduction can be very expensive when resolving the members of unions of a large number of array or tuple types. We used to rely on the eager reduction, but it is no longer necessary because a similar and more efficient reduction happens later (and in a deferred manner) when we compute the signature lists of union and intersection types.
With this PR we remove the unnecessary eager reduction. This makes our behavior more consistent since the eager reduction was never done for other types.
One example that directly benefits is this code in #26756. When requesting statement completion:
we currently spend 5-6 seconds grinding away before bringing up a completion list. With this PR the completion time drops to less than half a second.
Only one RWC project, fp-ts, is affected by this. Upon inspection the new errors in fp-ts look correct, and with the latest code here https://github.com/gcanti/fp-ts the errors are no longer present. I suspect the errors were not reported before because the eager reduction uses type parameter erasure which can lead to false positives.