I'm pretty new to Angular 2, so correct me if I'm inaccurate.
In Angular 1 the compiler is more general and dynamic, meaning that dirty checking code is a single code running over different components. However for performance sake in Angular 2, every component will get compiled to a generated code that handles bindings and dirty checking for that specific component. It means that depending on the component template, more specifically number of bindings, the generated code becomes larger.
When we use JIT, this is not important as this code doesn't go through the network and is generated in browser. But when using AOT it's going to be transferred from the server.
When the application is small, AOT will definitely result in smaller payload as the compiler is not going to be shipped to browser. But as the application grows, I assume this difference starts to decrease and maybe become inverted (does it?!). But I don't have a quantitative sense of it. Is it going to be a real issue for medium or large scale applications?
To answer the question "But as the application grows, I assume this difference starts to decrease and maybe become inverted (does it?!)" :
Yes it does, on a very large app the difference can be seen.
I asked a similar question on the webpack starter github, to quote the answer :
You might notice that the main file and chunk files are larger in build:prod:aot then in build:prod, this is perfectly normal since AOT produces more code. The total amount is less in AOT since the compiler is not part of the bundle, you can see it in the size of the vendor bundle. This also means that as your application grow, AOT will yield larger code since you add more AOT generated code but the compiler size is constant. The angular team is working on reducing the emitted code, one of the upcoming feature for this is a new View Engine that will reduce bundle size but will slightly effect performance (it's always a tradeoff)
Still, the apps starts way faster with AOT than JIT. Please see the issue, it seems the angular2 team is aware of this and plan on reducing this behavior.
https://github.com/AngularClass/angular2-webpack-starter/issues/1520
The issue to track on angular2 team side : https://github.com/angular/angular/issues/14013
UPDATE : Now live with Angular 4 https://github.com/angular/angular/blob/master/CHANGELOG.md#view-engine
We’ve made changes under to hood to what AOT generated code looks like. These changes should reduce the size of the generated code for your components by more than half in some cases. Read the Design Doc for the View Engine updates.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With