Recursive-related-check generic type references based on the id of their targets and type arguments #17984
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.
Fixes #17097
Fixes #17070
Fixes #16777
This change makes relating the following types faster:
Previously, relating the return types of map,
D<U> ===> B<U>
, would cause a recursive check. This recursion would continue until the depth limit was hit. However, no new information will result from relatingD<U> ===> B<U>
vsD<T> ===> B<T>
— one type parameter is interchangeable with any other in terms of relatability (with the exception of constrained type parameters).With this change, the check in
recursiveTypeRelatedTo
for whether a type is already being compared will treatA<T>
not by its identity but the identity ofA
and its type arguments. Previously,A<T>
andA<U>
would have different ids. Now, they both have ids like "111=0", ifA.id = 111
. Because bothT
andU
are unconstrained type parameters, they just get a simple index based on when they were first seen in the argument list. A type likeC<T, number, number, U, T>
would produce a key like112=0-33-33=1=0
where C.id=112 and number.id=33.Like #17947, this changes fixes immview and Immutable.js's oomemory crashes from 2.4.1. And it finishes about 10% faster. It also fixes the ng-typeview and monet crashes provided in #16777.
I tested the performance of this change and #17947. On TFS and Monaco, there is no performance difference with either change. I also ran the change on our real-world code corpus. Some duplicate error elaborations disappear from identical errors because of improved caching (in linq, RxJs, etc), but this is a slight improvement overall.