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

Introduce more caching and deferral into jsx checking #25302

Merged
merged 3 commits into from
Jun 28, 2018

Conversation

weswigham
Copy link
Member

Since, as of right now, the attributes and tag type of a jsx element do not play into the expression type, this defers checking of jsx elements. This deferral allows us to know that it is safe to cache many intermediate results while checking those tags (as we will not be in an inferential or contextual context), which we now do. We cache the result of getJsxNamespaceAt, if possible (as that resolution took a measurable slice of time when done as often as it was, since we were doing it a few times on the same tag name), and the sourceAttributesType (where we were spending slightly more than half our jsx checking time when it was uncached, as calculating the attributes type was done both during overload resolution (for stateless components) and checking). In extreme cases like a project that was shown to us, I see an order of magnitude improvement in semantic diagnostic time - in one file down from 4s to 0.5s.

This probably fixes #25085, since it seems to fix a similar issue in another project, though I can't know for sure.

For future work in this area, resolveCustomJsxElementAttributesType is about the only jsx-specific thing left that takes a measurable slice of time (though not very much compared to what I just started caching). It already caches the signatures it uses internally; but it may be worth adding a second layer of caching to it in the future.

@@ -16381,6 +16385,10 @@ namespace ts {
else {
checkExpression(node.closingElement.tagName);
}
}

function checkJsxElement(node: JsxElement, _checkMode: CheckMode | undefined): Type {
Copy link
Member

@RyanCavanaugh RyanCavanaugh Jun 28, 2018

Choose a reason for hiding this comment

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

Safe to remove _checkMode now?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, but I'll need to add it back in a week or two when I add more specific return types for jsx elements and once again track down all the places I need to flow it through again. I figured I'd just leave it here for later.

Copy link
Member

Choose a reason for hiding this comment

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

Might deserve a comment in case Andy sees it and removes it 😉

@weswigham weswigham requested a review from mhegazy June 28, 2018 20:04
@weswigham weswigham requested a review from sandersn June 28, 2018 20:17
@weswigham weswigham merged commit 2a19580 into microsoft:master Jun 28, 2018
@weswigham weswigham deleted the improve-jsx-perf branch June 28, 2018 21:43
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.

Typescript pulls entire MUI library - super slow type checking
3 participants