You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
With this PR we cache the results of isGenericObjectType and isGenericIndexType for unions and intersections. This improves total compile time of the repro in #36564 by about 6.5%.
Heya @ahejlsberg, I've started to run the perf test suite on this PR at a0546fc. You can monitor the build here. It should now contribute to this PR's status checks.
@ahejlsberg How do these predicates relate to couldContainTypeVariables? Is there a reason these are ObjectFlags and that uses a property?
Context: instantiateType is frequently called on types that can't be instantiated and it seems like we could save some time (~2% on the material-ui benchmark above, in my naive implementation) by checking one or more of these cached values.
How do these predicates relate to couldContainTypeVariables? Is there a reason these are ObjectFlags and that uses a property?
The isGenericObjectType and isGenericIndexType functions are used to determine whether conditional types, indexed access types, and index types should be resolved, or whether resolution should be deferred in a higher-order type of the particular kind. It is possible for these functions to return false even if the given type references type variables, e.g. for the type { foo: T } where T is a type variable.
The couldContainTypeVariables function computes whether a type possibly contains type variables, i.e. whether it possibly could be affected by instantiation. This function may return true even when the type references no type variables because it isn't possible to explore all types fully in depth. There's no good reason for this function to use a dedicated property. An ObjectFlags flag would be better.
In scenarios that are heavy on union and intersection type instantiation, it might make sense to first call couldContainTypeVariables since the cached result would allow us to bail out quicker.
Why do we only set those flags on union and intersection types? It looks like we might do non-trivial work for other types?
Do we need both sets of flags? I would guess that only one of the two makes sense for any given type or that, if both make sense, only the || of the values matters.
Edit - offline responses:
Claim is that it's only expensive for union and intersection types.
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.
With this PR we cache the results of
isGenericObjectType
andisGenericIndexType
for unions and intersections. This improves total compile time of the repro in #36564 by about 6.5%.