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(ivy): move setClassMetadata calls into a pure iife #33337
Conversation
All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the ℹ️ Googlers: Go here for more info. |
56644fe
to
f379dfa
Compare
A Googler has manually verified that the CLAs look good. (Googler, please make sure the reason for overriding the CLA status is clearly documented in these comments.) ℹ️ Googlers: Go here for more info. |
merge-assistance: this is a cherry-pick of a commit from #31939 that has been already reviewed and approved. I'm splitting up that PR to land stuff that is good to go. |
You can preview f379dfa at https://pr33337-f379dfa.ngbuilds.io/. |
I don't quite get why this is causing size regressions. The generated output before terser pass looks legit: https://hackmd.io/3mGNjS7nThmdq6qcAZQ_uw And oddly enough the original PR from @alxhub is not failing with this issue: #31939 |
Even more oddly, the original PR #31939 is failing the size test for aio but not for integration projects 😕 |
I've looked into this and think that I have identified the problem. It's related to how this PR changes the pattern that allows Build Optimizer (BO) to identify static properties for classes. In what BO calls "class fold", it tries to "fold" all static properties accesses after the class into a class declaration. We know these are static properties because it is how TS emits them.
These property assignments can reference variables, causing them to be retained even if the base class isn't used. Having these property assignment inside the class allows everything to be removed if the class is removed. Inside
This pattern breaks BOs identification of class static properties because In angular/angular-cli#15664 we got around this problem by identifying these calls and removing them before the "class fold" transform is ran. This way all properties went inside the class again. With this PR the shape changes again:
We could change CLI to also identify the new shape. But if we instead move the |
@filipesilva thanks for the info! the whole point of this change is to take away responsibility of the BO to do extra work. It would make no sense to make this change in the emit format and then keep on correcting the emit in BO. Let's iterate more on this change and get the code emitted correctly. This change can wait and is not RC blocking. |
This should help #33630 |
A Googler has manually verified that the CLAs look good. (Googler, please make sure the reason for overriding the CLA status is clearly documented in these comments.) ℹ️ Googlers: Go here for more info. |
This commit transforms the setClassMetadata calls generated by ngtsc from: ```typescript /*@__PURE__*/ setClassMetadata(...); ``` to: ```typescript /*@__PURE__*/ (function() { setClassMetadata(...); })(); ``` Without the IIFE, terser won't remove these function calls because the function calls have arguments that themselves are function calls or other impure expressions. In order to make the whole block be DCE-ed by terser, we wrap it into IIFE and mark the IIFE as pure. It should be noted that this change doesn't have any impact on CLI* with build-optimizer, which removes the whole setClassMetadata block within the webpack loader, so terser or webpack itself don't get to see it at all. This is done to prevent cross-chunk retention issues caused by webpack's internal module registry. * actually we do expect a short-term size regression while angular/angular-cli#16228 is merged and released in the next rc of the CLI. But long term this change does nothing to CLI + build-optimizer configuration and is done primarly to correct the seemingly correct but non-function PURE annotation that builds not using build-optimizer could rely on.
561ffee
to
559b341
Compare
All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the ℹ️ Googlers: Go here for more info. |
A Googler has manually verified that the CLAs look good. (Googler, please make sure the reason for overriding the CLA status is clearly documented in these comments.) ℹ️ Googlers: Go here for more info. |
You can preview 559b341 at https://pr33337-559b341.ngbuilds.io/. |
@@ -12,7 +12,7 @@ | |||
"master": { | |||
"uncompressed": { | |||
"runtime-es2015": 2987, | |||
"main-es2015": 461159, | |||
"main-es2015": 506857, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know this is temporary, but 😱 😱 😱
This commit transforms the setClassMetadata calls generated by ngtsc from: ```typescript /*@__PURE__*/ setClassMetadata(...); ``` to: ```typescript /*@__PURE__*/ (function() { setClassMetadata(...); })(); ``` Without the IIFE, terser won't remove these function calls because the function calls have arguments that themselves are function calls or other impure expressions. In order to make the whole block be DCE-ed by terser, we wrap it into IIFE and mark the IIFE as pure. It should be noted that this change doesn't have any impact on CLI* with build-optimizer, which removes the whole setClassMetadata block within the webpack loader, so terser or webpack itself don't get to see it at all. This is done to prevent cross-chunk retention issues caused by webpack's internal module registry. * actually we do expect a short-term size regression while angular/angular-cli#16228 is merged and released in the next rc of the CLI. But long term this change does nothing to CLI + build-optimizer configuration and is done primarly to correct the seemingly correct but non-function PURE annotation that builds not using build-optimizer could rely on. PR Close #33337
…ormat It's in a IIFE after angular/angular#33337 lands.
…ormat It's in a IIFE after angular/angular#33337 lands.
…ormat It's in a IIFE after angular/angular#33337 lands.
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
This commit transforms the setClassMetadata calls generated by ngtsc from:
to:
Without the IIFE, terser won't remove these function calls because the
function calls have arguments that themselves are function calls or other
impure expressions. In order to make the whole block be DCE-ed by terser,
we wrap it into IIFE and mark the IIFE as pure.
It should be noted that this change doesn't have any impact on CLI* with
build-optimizer, which removes the whole setClassMetadata block within
the webpack loader, so terser or webpack itself don't get to see it at
all. This is done to prevent cross-chunk retention issues caused by
webpack's internal module registry.
* actually we do expect a short-term size regression while angular/angular-cli#16228
is merged and released in the next rc of the CLI. But long term this
change does nothing to CLI + build-optimizer configuration and is done
primarly to correct the seeminly correct but non-function PURE annotation
that builds not using build-optimizer could rely on.