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

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.

主站蜘蛛池模板: 逊克县| 丹棱县| 弥勒县| 海原县| 调兵山市| 个旧市| 渭南市| 九江县| 乐业县| 合水县| 项城市| 江西省| 漯河市| 屯留县| 沭阳县| 鄂托克前旗| 通海县| 阿巴嘎旗| 黄山市| 龙泉市| 泰来县| 宕昌县| 衡南县| 公主岭市| 青龙| 新竹市| 潼南县| 饶平县| 班戈县| 重庆市| 昆山市| 鄯善县| 苍山县| 寻甸| 万州区| 通河县| 师宗县| 金山区| 子洲县| 永清县| 南靖县|