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

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.

主站蜘蛛池模板: 上高县| 甘肃省| 武平县| 辽中县| 浦北县| 盐亭县| 营口市| 庆云县| 洪雅县| 洱源县| 聂拉木县| 石楼县| 永安市| 临湘市| 宁陵县| 邹平县| 金寨县| 庐江县| 宁武县| 土默特左旗| 汕尾市| 林周县| 麻城市| 德州市| 镇宁| 武宁县| 辽源市| 大荔县| 湘乡市| 曲沃县| 城口县| 桐庐县| 偏关县| 云南省| 垦利县| 锡林浩特市| 兰溪市| 温宿县| 辰溪县| 朝阳区| 南岸区|