官术网_书友最值得收藏!

Change detection

In the web workers section, we already mentioned the opportunity to run the digest loop in the context of a different thread, instantiated as web worker. However, the implementation of the digest loop in AngularJS is not quite as memory-efficient and prevents the JavaScript virtual machine from doing further code optimizations, which allows for significant performance improvements. One such optimization is the inline caching (http://mrale.ph/blog/2012/06/03/explaining-js-vms-in-js-inline-caches.html).

The Angular team did a lot of research in order to discover different ways the performance and efficiency of the change detection could be improved. This led to the development of a brand new change detection mechanism.

As a result, Angular performs change detection in code that the framework directly generates from the templates of the components; the code is generated by the Angular compiler. The Angular compiler is a module of the framework which can process an Angular application, after that perform different optimizations on top of it, and in the end generate code that will perform much better than the source code that we have written.

There are two built-in code generation (also known as compilation) strategies:

  • Just-in-time (JIT) compilation: At runtime, Angular generates code that performs change detection on the entire application. The generated code is optimized for the JavaScript virtual machine, which provides a great performance boost.
  • Ahead-of-time (AOT) compilation: This is similar to JIT, with the difference that the code is being generated as part of the application's build process. It can be used for speeding the rendering up by not performing the compilation in the browser and also in environments that disallow eval(), such as ones with strict Content-Security-Policy (CSP) and Chrome extensions. We will discuss it further in the next sections of the book.

We will take a look at the new change detection mechanism and how we can configure it in Chapter 5, Getting Started with Angular Components and Directives.

主站蜘蛛池模板: 古蔺县| 华阴市| 龙山县| 綦江县| 延吉市| 富平县| 乌兰县| 乌兰察布市| 察隅县| 中山市| 罗定市| 东乌珠穆沁旗| 洪江市| 集贤县| 留坝县| 海南省| 厦门市| 皮山县| 潢川县| 正蓝旗| 延寿县| 宁城县| 临湘市| 定远县| 云霄县| 资阳市| 剑河县| 通州区| 客服| 枣阳市| 缙云县| 南充市| 巴林右旗| 左权县| 鹤壁市| 静海县| 汶川县| 嵊泗县| 大新县| 昌吉市| 呼和浩特市|