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

fix(language-service): create StaticReflector once only #32543

Closed
wants to merge 1 commit into from

Conversation

kyliau
Copy link
Contributor

@kyliau kyliau commented Sep 8, 2019

The creation of StaticReflector in createMetadataResolver() is a very expensive operation because it involves numerous module resolutions (on the order of hundreds) to initialize core Angular symbols.
Since the API of the Reflector does not provide the ability to invalidate its internal caches, StaticReflector has to be destroyed and recreated on every program change.
This has a HUGE impact on performance.
This PR fixes this problem by carefully invalidating all StaticSymbols in a file that has changed, thereby greatly reducing the overhead of recomputation on program change.

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • angular.io application / infrastructure changes
  • Other... Please describe:

What is the current behavior?

Issue Number: N/A

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

@kyliau kyliau requested review from a team as code owners September 8, 2019 08:13
@kyliau kyliau added area: language-service Issues related to Angular's VS Code language service state: WIP target: major This PR is targeted for the next major release labels Sep 8, 2019
@ngbot ngbot bot modified the milestone: needsTriage Sep 8, 2019
@kyliau
Copy link
Contributor Author

kyliau commented Sep 9, 2019

Need to rebase after #32098 is merged

@kyliau kyliau removed the state: WIP label Sep 9, 2019
@kyliau kyliau force-pushed the static_reflector branch 6 times, most recently from 2a154b0 to f1f7f6b Compare September 12, 2019 04:34
@kyliau kyliau requested a review from a team as a code owner September 12, 2019 04:34
@kyliau kyliau force-pushed the static_reflector branch 2 times, most recently from 711222b to 3fea08a Compare September 12, 2019 21:44
Copy link
Member

@petebacondarwin petebacondarwin left a comment

Choose a reason for hiding this comment

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

LGTM once it has been rebased.

Comment on lines +186 to +189
if (!symbols) {
return [];
}
this.symbolFromFile.delete(fileName);
Copy link
Member

Choose a reason for hiding this comment

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

If this is a StaticSymbol[] that is empty, this branch will still be hit right? Maybe we should do a check for undefined so that the file is still deleted from symbolFromFile if not undefined.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, I didn't quite get that.. The case of undefined is handled on line 186. If it's an empty array, it should still be deleted from the map, which is handled here.

Copy link
Member

Choose a reason for hiding this comment

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

my bad; I thought ![] === true

packages/language-service/src/typescript_host.ts Outdated Show resolved Hide resolved
The creation of StaticReflector in createMetadataResolver() is a very expensive operation because it involves numerous module resolutions.
To make matter worse, since the API of the Reflector does not provide the ability to invalidate its internal caches, it has to be destroyed and recreated on *every* program change.
This has a HUGE impact on performance.
This PR fixes this problem by carefully invalidating all StaticSymbols in a file that has changed, thereby reducing the overhead of recomputation on program change.
Comment on lines +186 to +189
if (!symbols) {
return [];
}
this.symbolFromFile.delete(fileName);
Copy link
Member

Choose a reason for hiding this comment

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

my bad; I thought ![] === true

@kyliau kyliau added the action: merge The PR is ready for merge by the caretaker label Oct 3, 2019
@kara kara added the merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note label Oct 3, 2019
@kara
Copy link
Contributor

kara commented Oct 3, 2019

merge-assistance: misko has global approval

@atscott atscott closed this in adb562b Oct 3, 2019
@kyliau kyliau deleted the static_reflector branch October 16, 2019 17:57
ODAVING pushed a commit to ODAVING/angular that referenced this pull request Oct 18, 2019
The creation of StaticReflector in createMetadataResolver() is a very expensive operation because it involves numerous module resolutions.
To make matter worse, since the API of the Reflector does not provide the ability to invalidate its internal caches, it has to be destroyed and recreated on *every* program change.
This has a HUGE impact on performance.
This PR fixes this problem by carefully invalidating all StaticSymbols in a file that has changed, thereby reducing the overhead of recomputation on program change.

PR Close angular#32543
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Nov 16, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker area: language-service Issues related to Angular's VS Code language service cla: yes merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note target: major This PR is targeted for the next major release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants