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

perf(compiler-cli): skip analysis in incremental builds for files wit… #42562

Closed
wants to merge 2 commits into from

Conversation

JoostK
Copy link
Member

@JoostK JoostK commented Jun 12, 2021

…hout Angular behavior

In an incremental rebuild, the compiler attempts to reuse as much
analysis data from a prior compilation as possible to avoid doing the
analysis work again. For source files without Angular behavior however,
no analysis data would be recorded such that the source file had to be
reanalyzed each rebuild, even if it has not changed.

This commit avoids the analysis of such source files by registering
these files as not containing any Angular behavior; allowing subsequent
rebuilds to avoid the analysis work.

@JoostK JoostK added target: patch This PR is targeted for the next patch release area: compiler Issues related to `ngc`, Angular's template compiler labels Jun 12, 2021
@ngbot ngbot bot modified the milestone: Backlog Jun 12, 2021
@google-cla google-cla bot added the cla: yes label Jun 12, 2021
@JoostK JoostK force-pushed the ngtsc/perf/avoid-analysis branch from 944eb8a to 397d115 Compare June 12, 2021 15:12
@JoostK JoostK marked this pull request as ready for review June 12, 2021 18:00
@JoostK JoostK added the action: review The PR is still awaiting reviews from at least one requested reviewer label Jun 12, 2021
@JoostK JoostK force-pushed the ngtsc/perf/avoid-analysis branch from 397d115 to 3fb8f04 Compare July 13, 2021 19:37
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.

This seems like a good optimisation. Thanks @JoostK.

One thing that slightly worries me is the use of null and undefined to have context specific meanings.

I think we should discuss the idea, going forward, of using well defined singleton branded objects that are then self-documenting, rather than relying upon documented specialized use of null.

For example in this case instead of null we could have: const NO_ANGULAR_TRAITS = { _brand: 'source file with no Angular traits' };.

@JoostK
Copy link
Member Author

JoostK commented Jul 14, 2021

The null/undefined distinction is indeed not the nicest. Maybe an enum with two variants would be nicer.

Though there is precedent for using the null/undefined pattern elsewhere in the compiler code:

/**
* Produce a shim `ts.SourceFile` if `fileName` refers to a shim file which should exist in the
* program.
*
* If `fileName` does not refer to a potential shim file, `null` is returned. If a corresponding
* base file could not be determined, `undefined` is returned instead.
*/
maybeGenerate(fileName: AbsoluteFsPath): ts.SourceFile|null|undefined {

@JoostK JoostK added action: merge The PR is ready for merge by the caretaker action: presubmit The PR is in need of a google3 presubmit and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Jul 14, 2021
@AndrewKushnir
Copy link
Contributor

Presubmit.

@AndrewKushnir AndrewKushnir added merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note and removed action: presubmit The PR is in need of a google3 presubmit labels Jul 14, 2021
@AndrewKushnir
Copy link
Contributor

Merge assistance: NgBot doesn't change the status to fully "green" due to one more reviewer assigned, but since Pete reviewed the change it might be ok to proceed without extra reviews? // cc @alxhub

*/
priorAnalysisFor(sf: ts.SourceFile): AnalysisT[]|null;
priorAnalysisFor(sf: ts.SourceFile): AnalysisT[]|null|undefined;
Copy link
Member

Choose a reason for hiding this comment

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

Is there much of a difference between using null here to indicate "analyzed, but had no traits" and using an empty array instead? I really try to avoid using null and undefined in the same type to indicate two different states.

Copy link
Member Author

@JoostK JoostK Jul 20, 2021

Choose a reason for hiding this comment

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

I considered that but found the null|undefined more explicit; the handling code in TraitCompiler.analyze is now forced to special-case putting null into this.filesWithoutTraits, whereas an empty array would not have required a change based on the type-system (and missed the necessity to update this.filesWithoutTraits)

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't feel particularly strongly about this, though, so happy to switch to [] if you think that's desirable.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, updated. That actually allowed most of the earlier changes to be reverted.

…hout Angular behavior

In an incremental rebuild, the compiler attempts to reuse as much
analysis data from a prior compilation as possible to avoid doing the
analysis work again. For source files without Angular behavior however,
no analysis data would be recorded such that the source file had to be
reanalyzed each rebuild, even if it has not changed.

This commit avoids the analysis of such source files by registering
these files as not containing any Angular behavior; allowing subsequent
rebuilds to avoid the analysis work.
@JoostK JoostK force-pushed the ngtsc/perf/avoid-analysis branch from 3fb8f04 to a0cb10f Compare July 20, 2021 20:10
@JoostK JoostK added merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note and removed merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note labels Jul 20, 2021
@JoostK
Copy link
Member Author

JoostK commented Jul 20, 2021

merge-assistance: presubmit succeeded on an earlier revision; this should be fine to merge.

dylhunn pushed a commit that referenced this pull request Jul 21, 2021
…hout Angular behavior (#42562)

In an incremental rebuild, the compiler attempts to reuse as much
analysis data from a prior compilation as possible to avoid doing the
analysis work again. For source files without Angular behavior however,
no analysis data would be recorded such that the source file had to be
reanalyzed each rebuild, even if it has not changed.

This commit avoids the analysis of such source files by registering
these files as not containing any Angular behavior; allowing subsequent
rebuilds to avoid the analysis work.

PR Close #42562
@dylhunn dylhunn closed this in 5fb23ec Jul 21, 2021
@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 Aug 21, 2021
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: compiler Issues related to `ngc`, Angular's template compiler 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: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants