Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Angular Performance 101

Angular Performance 101

From JS-IL 2014, given on June 17, 2014.

Aviv Ben-Yosef

June 17, 2014
Tweet

More Decks by Aviv Ben-Yosef

Other Decks in Programming

Transcript

  1. Watch Expressions $scope.$watch() {{ stuff }} ng-show=“list.length > 0” isolated

    scope bindings: {foo: ‘=’} filters: {{ date | fromNow }} ng-repeat Basically everything
  2. When digest runs User actions (ng-click, ng-model, etc.) $http responses

    $q promises resolved $timeout / $interval $scope.$apply() / $scope.$digest() Basically: a lot of things
  3. You click and the screen freezes for a while The

    only* performance issue that is angular’s fault
  4. One Screen is Slow That screen has bad scopes: Too

    many watches Watch handlers that take too long
  5. Making Watches Faster Switch deep watch with $watchCollection $scope.$watch(‘myList’, function()

    {}, true); ! $scope.$watchCollection(‘myList’, function() {});
  6. Making Watches Faster Deep watch a subset $scope.$watch(‘myList’, function() {},

    true); ! $scope.$watch( function() {return _.pluck($scope.myList, ‘id’);}, function() {}, true);
  7. ng-repeat is your enemy Use track by <div ng-repeat=“task in

    tasks track by task.id”> http://bit.ly/1kyvet7
  8. Have Less Watches ng-hide & ng-show elements are still there,

    consider using ng-if Consider replacing filters with
 pre-calculated values
  9. Thank You! Aviv Ben-Yosef @avivby www.deflect.io ! My angular &

    web development newsletter www.codelord.net