Skip to content

Use couldContainTypeVariables to short-circuit instantiateType #36951

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

Merged
merged 1 commit into from
Feb 25, 2020

Conversation

amcasey
Copy link
Member

@amcasey amcasey commented Feb 21, 2020

This is particularly impactful for large unions of string literals.

This is particularly impactful for large unions of string literals.
@amcasey
Copy link
Member Author

amcasey commented Feb 21, 2020

The check could be lifted out to instantiateType to short-circuit the whole call to instantiateTypeWorker, but that was about 1% slower when I ran the material-ui benchmark. Of course, 1% might be worth it for clearer code. Thoughts?

@amcasey
Copy link
Member Author

amcasey commented Feb 21, 2020

Not running the perf test since only unions and intersections are affected.

@amcasey
Copy link
Member Author

amcasey commented Feb 21, 2020

I intentionally made this a very narrow change. If we wanted to go broader, we could have instantiateType and couldContainTypeVariable share their tree walks (probably by having instantiateType also return whether it encountered a type variable). If we wanted to go really nuts, it could also indicate whether the instantiated type contains type variables. Thoughts?

Copy link
Member

@weswigham weswigham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Considering we already have the same check in the flags & Object + objectFlags & ObjectFlags.Anonymous case, adding this check seems fine. We can at least start with this and iterate if we need to.

@amcasey
Copy link
Member Author

amcasey commented Feb 22, 2020

@weswigham I was surprised that the value didn't seem to be cached in that case. I think it will be as of #36947.

@amcasey amcasey merged commit 865c120 into microsoft:master Feb 25, 2020
@amcasey amcasey deleted the InstantiateCouldContain branch February 25, 2020 01:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants