Skip to content
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

Recursive-related-check generic type references based on the id of their targets and type arguments #17984

Merged
merged 5 commits into from
Aug 23, 2017

Conversation

sandersn
Copy link
Member

@sandersn sandersn commented Aug 23, 2017

Fixes #17097
Fixes #17070
Fixes #16777

This change makes relating the following types faster:

interface B<T> {
  contents: T[]
  map<U>(f: (t: T) => U): B<U>
}
interface D<T> extends B<T> {
  contents: List<T>
  map<U>(f: (t: T) => U): D<U>
}

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 relating D<U> ===> B<U> vs D<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 treat A<T> not by its identity but the identity of A and its type arguments. Previously, A<T> and A<U> would have different ids. Now, they both have ids like "111=0", if A.id = 111. Because both T and U are unconstrained type parameters, they just get a simple index based on when they were first seen in the argument list. A type like C<T, number, number, U, T> would produce a key like 112=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.

@mhegazy
Copy link
Contributor

mhegazy commented Aug 31, 2017

@sandersn we need to port this to release-2.5

@sandersn
Copy link
Member Author

Done. This is now in release-2.5

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
4 participants