You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
size regression due to host view factories generated for non-entryComponents #19857
[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question
Current behavior
in v4 the AOT compiler generated host view factories only for entryComponents in v5.0.0.rc2 we generate them even for components that are not marked as entryComponents.
Example in aio is SearchResultsComponent, which is not marked as entryComponent. When upgrading from 5.0.0-beta.3, I noticed that we now started generating View_SearchResultsComponent_Host_0 for this component. And we do it in a way that tightly couples it with the rest of the component factories, so it can't be eliminated.
Is this expected? My understanding is that the host factories are only needed for entryComponents.
I can't estimate how significant this size regression is for aio because I'm unfortunately updating various dependencies. Due to bugs and api incompatibilities can't isolate the change just to the change of the compiler. Overall I'm looking for about 30kb size increase which might or might not contain other size regressions.
Ich kehre zurück am 01.11.2017.
Ich werde Ihre Nachricht nach meiner Rückkehr beantworten.
In dringenden Fällen senden Sie bitte eine Kopie Ihrer E-Mail für
technische Angelegenheiten an entwicklung@arxes-tolina.de, ansonsten an
info@arxes-tolina.de. Ein anderer Mitarbeiter wird sich dann Ihrer E-Mail
annehmen.
Hinweis: Dies ist eine automatische Antwort auf Ihre Nachricht "Re:
[angular/angular] size regression due to host view factories generated for
non-entryComponents (#19857)" gesendet am 23.10.2017 13:05:11.
Diese ist die einzige Benachrichtigung, die Sie empfangen werden, während
diese Person abwesend ist.
@IgorMinar yes, AOT always used to generate host view factories for all components, as entryComponents could be introduced by a downstream dependency that is compiled in a separate compilation unit.
The generated code here looks really wrong (it is after uglify and webpack though). The styles don't use the component factory, and the component factory should have been stored in a top level variable.
The code above is incorrect. The styles_FileNotFoundSearchComponent should be [] and, if it had it correct value, would have been tree-shaken.
Removing uglify from the configuration, as described above by @IgorMinar, shows that the ngc is emitting the correct code. We also bashed the writeFile callback of the compiler_host.js in ng to save the intermediate output and the ngc output is correct.
It looks like the code gets mangled in the uglify step.
We tried executing uglifyjs directly, using several versions, but have not been able to duplicate the bug nor duplicate the output format so something might be going wrong in the uglify plugin or other code prior to uglify.
@hansl Is taking over the investigation to narrow down where the problem is in the webpack chain.
var SearchResultsComponentNgFactory = createComponentFactory("aio-search-results",
The generated code has a top level function call createComponentFactory (and a few others) that are no longer being marked as @PURE, so uglify considers them as calls with potential side-effect and retains all of the code. (the code then gets inlined in various weird ways to decrease the size slightly, but it's essentially all retained.
In the past we used to have special code in build-optimizer that would look for a few handpicked function calls in the generated code and mark them as pure. We however improved other bits and managed to inline core modules together with ng factories, which now means that we no longer can identify these calls via angular_core webpack module import, but those no longer exist, so we don't match these functions any more. This means that all of the generated code is fully retained even with build-optimizer turned on.
@filipesilva created a patch for build-optimizer that uses different approach to marking these functions as pure - we assume that all of the generated code has no non-local side-effects, so we prefix all the top level function calls with pure.
I tested this version of the optimization, and indeed all the generated code got marked as pure and removed by uglify if not retained by the rest of the app. This resulted in 35KB savings for aio.
@filipesilva is working on getting the patch into a release of build-optimizer now.
@tbosch@chuckjaz Now that we understand this, my question is: should we consider emitting the pure annotation directly from ngc for all generated code? That way people not using build-optimizer but using uglify would benefit.
I don't like generating uglify-specific instructions in our code, but it makes a huge impact on size and doesn't harm anything else. What do you think?
@IgorMinar If users are not using the build optimizer, a lot of other things are retained too, right?. So I would rather not add the dependency of our codegen to uglify specific comments but rather recommend our build optimizer in a stronger way.
Activity
maxkoretskyi commentedon Oct 23, 2017
I reported this behavior even for v4 in this issue
IgorMinar commentedon Oct 23, 2017
@MaximusK in my case the issue occurs with AOT compilation
skatterwe commentedon Oct 23, 2017
alexzuza commentedon Oct 23, 2017
I tried it with 4.3.6 and it also generated Host factories for non-entryComponents
Here's piece of the corresponding code:
https://github.com/angular/angular/blob/4.3.x/packages/compiler/src/aot/compiler.ts#L303
AFAIK only Compiler in JIT mode doesn't generate such factories for non-entryComponents
https://github.com/angular/angular/blob/4.3.x/packages/compiler/src/jit/compiler.ts#L174-L199
Jit compiler only generates host factories if:
compiler._compileModuleAndAllComponentsentryComponentsmetadataentryComponentsmetadatabootstrapmetadataSo i think it was intended to generate host factories for all component in AOT but i don't know why...
tbosch commentedon Oct 23, 2017
@IgorMinar yes, AOT always used to generate host view factories for all components, as
entryComponentscould be introduced by a downstream dependency that is compiled in a separate compilation unit.tbosch commentedon Oct 23, 2017
The generated code here looks really wrong (it is after uglify and webpack though). The styles don't use the component factory, and the component factory should have been stored in a top level variable.
tbosch commentedon Oct 23, 2017
@chuckjaz Steps to reproduce the incorrect code above (from @IgorMinar):
IgorMinar commentedon Oct 23, 2017
you can also disable the uglify completely by commenting it out in the webpack config. that will show you what we feed into uglify.
chuckjaz commentedon Oct 23, 2017
The code above is incorrect. The
styles_FileNotFoundSearchComponentshould be[]and, if it had it correct value, would have been tree-shaken.Removing uglify from the configuration, as described above by @IgorMinar, shows that the
ngcis emitting the correct code. We also bashed thewriteFilecallback of thecompiler_host.jsinngto save the intermediate output and thengcoutput is correct.It looks like the code gets mangled in the uglify step.
We tried executing uglifyjs directly, using several versions, but have not been able to duplicate the bug nor duplicate the output format so something might be going wrong in the uglify plugin or other code prior to uglify.
@hansl Is taking over the investigation to narrow down where the problem is in the webpack chain.
4 remaining items
IgorMinar commentedon Oct 24, 2017
I got to the bottom of this!!!
if I disable uglify I see this snippet of code in the bundle
The thing to notice is this line:
The generated code has a top level function call
createComponentFactory(and a few others) that are no longer being marked as @PURE, so uglify considers them as calls with potential side-effect and retains all of the code. (the code then gets inlined in various weird ways to decrease the size slightly, but it's essentially all retained.In the past we used to have special code in build-optimizer that would look for a few handpicked function calls in the generated code and mark them as pure. We however improved other bits and managed to inline core modules together with ng factories, which now means that we no longer can identify these calls via
angular_corewebpack module import, but those no longer exist, so we don't match these functions any more. This means that all of the generated code is fully retained even with build-optimizer turned on.@filipesilva created a patch for build-optimizer that uses different approach to marking these functions as pure - we assume that all of the generated code has no non-local side-effects, so we prefix all the top level function calls with pure.
I tested this version of the optimization, and indeed all the generated code got marked as pure and removed by uglify if not retained by the rest of the app. This resulted in 35KB savings for aio.
@filipesilva is working on getting the patch into a release of build-optimizer now.
@tbosch @chuckjaz Now that we understand this, my question is: should we consider emitting the pure annotation directly from ngc for all generated code? That way people not using build-optimizer but using uglify would benefit.
I don't like generating uglify-specific instructions in our code, but it makes a huge impact on size and doesn't harm anything else. What do you think?
filipesilva commentedon Oct 24, 2017
angular/devkit#236 should address @IgorMinar's findings.
hansl commentedon Oct 24, 2017
@IgorMinar The fix in build-optimizer has been released 20 minutes ago.
tbosch commentedon Oct 24, 2017
@IgorMinar If users are not using the build optimizer, a lot of other things are retained too, right?. So I would rather not add the dependency of our codegen to uglify specific comments but rather recommend our build optimizer in a stronger way.
IgorMinar commentedon Oct 25, 2017
fixed by angular/devkit#236
IgorMinar commentedon Oct 25, 2017
released as @angular/devkit@0.0.31
build(aio): temporarily increaze the size limit until the regressions…
build(aio): temporarily increaze the size limit until the regressions…
build(aio): temporarily increaze the size limit until the regressions…
angular-automatic-lock-bot commentedon Sep 12, 2019
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.