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): optimize NgModule emit for standalone components #49837

Closed
wants to merge 1 commit into from

Conversation

alxhub
Copy link
Member

@alxhub alxhub commented Apr 13, 2023

NgModules which import standalone components currently list those components in their injector definitions, because we assume that any standalone component may export providers from its own imports.

This commit adds an optimization for that emit, which attempts to statically analyze the NgModule imports and determine which standalone components, if any are present, do not export providers and thus can be omitted.

This analysis is imperfect, because some imported components may be declared outside of the current compilation, or transitively import types which are declared outside the compilation. These types are therefore assumed to carry providers and so the optimization isn't applied to them.

@alxhub alxhub added the target: patch This PR is targeted for the next patch release label Apr 13, 2023
@alxhub alxhub force-pushed the ngtsc/standalone/providers branch 3 times, most recently from 15a81a1 to 1946b14 Compare April 13, 2023 23:35
*/
mayContainProviders(
ref: Reference<ClassDeclaration>,
callback?: (importRef: Reference<ClassDeclaration>) => void): boolean {
Copy link
Contributor

Choose a reason for hiding this comment

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

What is callback here supposed to be? I also don't see any calls to this function where the callback isn't passed so does it have to be optional?

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 renamed it to dependencyCallback and added jsdocs.

It's optional because, for the conceptual operation of "does X contain exported providers?", a consumer may only be interested in the answer and not in recording information about dependencies (for example, if producing a diagnostic instead of emitting code).

packages/compiler-cli/src/ngtsc/metadata/src/providers.ts Outdated Show resolved Hide resolved
Copy link
Member

@devversion devversion left a comment

Choose a reason for hiding this comment

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

LGTM overall. Thanks Alex

@jessicajaniuk jessicajaniuk added the area: compiler Issues related to `ngc`, Angular's template compiler label Apr 14, 2023
@ngbot ngbot bot added this to the Backlog milestone Apr 14, 2023
@alxhub alxhub requested a review from atscott April 14, 2023 15:18
@alxhub alxhub dismissed atscott’s stale review April 14, 2023 15:18

Comments addressed!

@alxhub alxhub force-pushed the ngtsc/standalone/providers branch from 1946b14 to aad4dec Compare April 14, 2023 15:19
NgModules which import standalone components currently list those components
in their injector definitions, because we assume that any standalone
component may export providers from its own imports.

This commit adds an optimization for that emit, which attempts to statically
analyze the NgModule imports and determine which standalone components, if
any are present, do not export providers and thus can be omitted.

This analysis is imperfect, because some imported components may be declared
outside of the current compilation, or transitively import types which are
declared outside the compilation. These types are therefore _assumed_ to
carry providers and so the optimization isn't applied to them.
@alxhub alxhub force-pushed the ngtsc/standalone/providers branch from aad4dec to bde2b44 Compare April 14, 2023 16:04
@alxhub alxhub added action: global presubmit The PR is in need of a google3 global presubmit action: merge The PR is ready for merge by the caretaker and removed action: global presubmit The PR is in need of a google3 global presubmit labels Apr 14, 2023
@jessicajaniuk jessicajaniuk added target: rc This PR is targeted for the next release-candidate and removed target: patch This PR is targeted for the next patch release labels Apr 17, 2023
@jessicajaniuk
Copy link
Contributor

@alxhub I've updated this to target: rc due to conflicts with 15.2.x. Feel free to create a patch PR if you'd like it to hit 15.2.x.

@jessicajaniuk
Copy link
Contributor

This PR was merged into the repository by commit 78c76ce.

jessicajaniuk pushed a commit that referenced this pull request Apr 17, 2023
…49837)

NgModules which import standalone components currently list those components
in their injector definitions, because we assume that any standalone
component may export providers from its own imports.

This commit adds an optimization for that emit, which attempts to statically
analyze the NgModule imports and determine which standalone components, if
any are present, do not export providers and thus can be omitted.

This analysis is imperfect, because some imported components may be declared
outside of the current compilation, or transitively import types which are
declared outside the compilation. These types are therefore _assumed_ to
carry providers and so the optimization isn't applied to them.

PR Close #49837
@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 May 18, 2023
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 target: rc This PR is targeted for the next release-candidate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants