Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Remove side effects to improve Ivy tree shaking in Closure #35846

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

Closed
wants to merge 5 commits into from

Conversation

dgp1130
Copy link
Contributor

@dgp1130 dgp1130 commented Mar 4, 2020

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix

What is the current behavior?

Closure does not tree shake unused components built with Ivy.

Issue Number: http://b/149874196, http://b/149874638.

What is the new behavior?

Closure will now tree shake unused components built with Ivy.

Does this PR introduce a breaking change?

  • No

Other information

This is effectively identical to #35769, just targeting patch branch. I cherry-picked all the commits onto a new branch based on 9.0.x.

dgp1130 added 5 commits March 3, 2020 15:59
…inner function (angular#35769)

This is useful for propagating return values without them being converted to a string. It still provides the same guarantees to Closure, which will assume that the function invoked is pure and can be tree-shaken accordingly.

PR Close angular#35769

(cherry picked from commit 4052dd8)
…ular#35769)

This causes all the `make*Decorator()` functions to be considered pure and to be eligible for associated tree shaking by Closure.

PR Close angular#35769

(cherry picked from commit dc6a791)
)

This marks the function are "pure" and eligible to be tree shaken by Closure. Without this, initializing `ngDevMode` is considered a side effect which prevents this function from being tree shaken and also any component which calls it.

PR Close angular#35769

(cherry picked from commit ba36127)
…#35769)

`ɵɵNgOnChangesFeature()` would set `ngInherit`, which is a side effect and also not necessary. This was pulled out to module scope so the function itself can be pure. Since it only curries another function, the call is entirely unnecessary. Updated the compiler to only generate a reference to this function, rather than a call to it, and removed the extra curry indirection.

PR Close angular#35769

(cherry picked from commit 9cf85d2)
…r#35769)

`ɵɵgetInheritedFactory()` is called from generated code for a component which extends another class. This function is detected by Closure to have a side effect and is not able to tree shake the component as a result. Marking it with `noSideEffects()` tells Closure it can remove this function under the relevant tree shaking conditions.

PR Close angular#35769

(cherry picked from commit c195d22)
@dgp1130 dgp1130 requested a review from IgorMinar March 4, 2020 00:03
@dgp1130 dgp1130 changed the title Side effects Remove side effects to improve Ivy tree shaking in Closure Mar 4, 2020
@atscott atscott added PR target: patch-only area: compiler Issues related to `ngc`, Angular's template compiler area: core Issues related to the framework runtime labels Mar 4, 2020
@ngbot ngbot bot modified the milestone: needsTriage Mar 4, 2020
Copy link
Contributor

@IgorMinar IgorMinar left a comment

Choose a reason for hiding this comment

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

lgtm. already pre-reviewed in the original PR.

thanks!

global approval

@IgorMinar IgorMinar added the action: merge The PR is ready for merge by the caretaker label Mar 6, 2020
matsko pushed a commit that referenced this pull request Mar 6, 2020
…inner function (#35769) (#35846)

This is useful for propagating return values without them being converted to a string. It still provides the same guarantees to Closure, which will assume that the function invoked is pure and can be tree-shaken accordingly.

PR Close #35769

(cherry picked from commit 4052dd8)

PR Close #35846
matsko pushed a commit that referenced this pull request Mar 6, 2020
) (#35846)

This causes all the `make*Decorator()` functions to be considered pure and to be eligible for associated tree shaking by Closure.

PR Close #35769

(cherry picked from commit dc6a791)

PR Close #35846
matsko pushed a commit that referenced this pull request Mar 6, 2020
…35846)

This marks the function are "pure" and eligible to be tree shaken by Closure. Without this, initializing `ngDevMode` is considered a side effect which prevents this function from being tree shaken and also any component which calls it.

PR Close #35769

(cherry picked from commit ba36127)

PR Close #35846
matsko pushed a commit that referenced this pull request Mar 6, 2020
…#35846)

`ɵɵNgOnChangesFeature()` would set `ngInherit`, which is a side effect and also not necessary. This was pulled out to module scope so the function itself can be pure. Since it only curries another function, the call is entirely unnecessary. Updated the compiler to only generate a reference to this function, rather than a call to it, and removed the extra curry indirection.

PR Close #35769

(cherry picked from commit 9cf85d2)

PR Close #35846
matsko pushed a commit that referenced this pull request Mar 6, 2020
#35846)

`ɵɵgetInheritedFactory()` is called from generated code for a component which extends another class. This function is detected by Closure to have a side effect and is not able to tree shake the component as a result. Marking it with `noSideEffects()` tells Closure it can remove this function under the relevant tree shaking conditions.

PR Close #35769

(cherry picked from commit c195d22)

PR Close #35846
@matsko
Copy link
Contributor

matsko commented Mar 6, 2020

Landed as 000c834

@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 Apr 6, 2020
@dgp1130 dgp1130 deleted the side-effects branch June 8, 2020 23:19
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 area: core Issues related to the framework runtime cla: yes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants