2016-08-05 75 views
5

精彩的開發人員,我需要一點幫助,澄清爲什麼Angular 2比Angular 1更高性能?爲什麼Angular 2比Angular 1有更好的性能?

在網上搜索後,我想出了這個相關的解釋從Er Shahbaz Sharif in a Quora discussion

Angular 2 is using Hierarchical Dependency Injection system which is major performance booster. 
Angular 2 implements unidirectional tree based change detection which again increases performance . 
As per ng-conf meetup, angular 2 is 5 times faster as compared to angular 1 

在同一個討論的其他解釋似乎徘徊在這一點。

難道有人請爲我澄清爲什麼這兩個因素(和其他人,如果有的話)有助於提升Angular 2的性能?非常感謝。

回答

2

Angular2 - 不做深對象compairson。如果項目被添加到/從數組中移除,更改檢測將無法檢測到它。對象屬性一樣,只要它們不直接從視圖中綁定即可。

  • 雙向綁定被分割爲將檢測到的更改從根節點傳播到葉節點。

  • 從孩子到父母的變化僅通過顯式事件(輸出)傳播,僅傳播給直接父母。

  • ChangeDetectionStrategy.OnPush在沒有輸入值發生變化時不運行組件的變更檢測。這修剪了組件的子樹,根本不運行變更檢測。

  • 代碼(尤其是更改檢測代碼)的編寫方式可以儘可能多地由JS VM優化。

https://www.quora.com/What-is-the-difference-between-angularjs-and-angular2

1

其中一個原因是業績變化檢測環路的存在的可能性。

  • Angular1使得它的性能與它的輪詢狀態有關。在每個摘要循環中,框架會檢查應用程序中數百或數千個值是否有變化。
  • Angular 2將允許開發人員爲變更檢測機制提供一些保證,以避免掃描部件樹。欲瞭解更多詳情,你可以在here找到更多。