对于编译器,我对Angular 1 vs 2的理解:
在Angular 1中,编译器是更通用和动态的,这意味着脏检查代码是运行在不同组件上的单个代码.然而,为了在角度2的性能上,每个组件都将被编译成一个生成的代码,用于处理该特定组件的绑定和脏检查.这意味着根据组件模板,更具体地说是绑定数量,生成的代码变大.
当我们使用JIT时,这并不重要,因为这个代码不会通过网络并在浏览器中生成.但是当使用AOT时,它将从服务器传输.
问题(可能):
当应用程序很小时,AOT肯定会导致更小的有效载荷,因为编译器不会被发送到浏览器.但随着应用程序的发展,我认为这种差异开始减少,也许会变成倒置(是吗?但我没有定量的感觉.中型或大型应用将会成为一个真正的问题吗?
解决方法
是的,在一个非常大的应用程序上,差异可以看出.
我在webpack启动器github上提出了一个类似的问题,引用答案:
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)
不过,与JIT相比,AOT的应用程序开始速度更快.
请看这个问题,似乎角色2团队意识到这一点,并计划减少这种行为.
https://github.com/AngularClass/angular2-webpack-starter/issues/1520
在角色2队方面跟踪的问题:https://github.com/angular/angular/issues/14013
更新:现在生活在角度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.