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

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.

主站蜘蛛池模板: 榆中县| 海原县| 阿荣旗| 榆树市| 江口县| 田阳县| 乌拉特后旗| 凤山市| 遵义县| 六安市| 汉源县| 桐乡市| 陇西县| 东平县| 永德县| 涞源县| 芦溪县| 合作市| 民乐县| 浦江县| 勐海县| 苏州市| 乌审旗| 古浪县| 布尔津县| 苏尼特左旗| 沛县| 西乌珠穆沁旗| 阿合奇县| 大埔区| 百色市| 安丘市| 法库县| 卓尼县| 西平县| 泰和县| 柏乡县| 如东县| 镇原县| 林口县| 腾冲县|