angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

build optimizer flag only reduces app size 0.1% max

Open m4mbart opened this issue 9 years ago • 5 comments

Bug Report or Feature Request (mark with an x)

- [ x] bug report -> please search issues before submitting (though not sure it is a bug)
- [ ] feature request

Versions.

@angular/cli: 1.4.4 node: 6.10.3 os: darwin x64 @angular/animations: 4.1.3 @angular/common: 4.1.3 @angular/compiler: 4.1.3 @angular/core: 4.1.3 @angular/forms: 4.1.3 @angular/http: 4.1.3 @angular/platform-browser: 4.1.3 @angular/platform-browser-dynamic: 4.1.3 @angular/router: 4.1.3 @angular/cli: 1.4.4 @angular/compiler-cli: 4.1.3 @angular/language-service: 4.1.3 typescript: 2.3.4

Repro steps.

I ran these commands and compared the output: ng build --prod --build-optimizer --aot false --env=dev-nl --sm false --base-href="/app/" ng build --prod --aot false --env=dev-nl --sm false --base-href="/app/"

Command outputs:

optimized not-optimized

Desired functionality.

angular.io apparantly reduced there output size by 50%. I do not expect results anywhere near that size. But I would have thought to gain a little more then 0.1%. What do you think about this?

m4mbart avatar Oct 03 '17 10:10 m4mbart

Oh my.. noticing --aot false just now, as I am first testing this functionality on the Dev environment. Will be back with new results soon...

m4mbart avatar Oct 03 '17 10:10 m4mbart

Ok new results, this time with AOT enabled:

Commands

ng build --prod --env=dev-nl --sm false --base-href="/app/" ng build --prod --build-optimizer --env=dev-nl --sm false --base-href="/app/"

Outputs

not-optimized optimized

That still is only 1% max. Is that in line with what others are experiencing?

m4mbart avatar Oct 03 '17 11:10 m4mbart

The build optimizer is designed to remove unused code with the primary target being vendor libraries (angular, etc.). However, the more of the vendor libraries the application uses the less the build optimizer can do. Also, as an application grows larger the ratio of vendor code to application code moves toward application code; making the potential savings percentage decrease as the ratio shifts toward the application.

In general, rather than the total size of the application, the more important metric is the size of the files on the critical path. These affect the first render time of the application and in this case they would be inline, polyfills, main, and styles. A decrease here will lower the wait time a user will experience before using the application. This is in contrast to the lazy loaded bundles; which can be prefetched in the background while the user is interacting with the application.

clydin avatar Oct 03 '17 13:10 clydin

Ah thanks for the explanation., I was not aware that the build-optimizer was mainly intended for libraries and not actual application code. Although it makes sense, because all code we write should be in use and not stripped away like library code. I Guess the application/library ratio of our codebase is the reason for the small gain.

m4mbart avatar Oct 05 '17 15:10 m4mbart

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.