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

Angular Performance Tuning

Angular Performance Tuning

for large Apps (presented at JSUnconf)

Avatar for damienklinnert

damienklinnert

April 26, 2014
Tweet

More Decks by damienklinnert

Other Decks in Programming

Transcript

  1. Unfortunately [...] it is easy to build slow apps when

    you don't know what you are doing. — Misko Hevery
  2. Use ng-if instead of ng-show <button ng-click="expanded = !expanded"> Show

    details </button> <div ng-if="expanded"> <div ng-include="complex.html"></div> </div> docs.angularjs.org/api/ng/directive/ngIf
  3. bind-once <li bindonce ng-repeat="person in persons"> <span bo-text="person.name"></span> </li> //

    see bo-href, bo-src, bo-class, bo-html github.com/Pasvaz/bindonce
  4. Precalculate properties // bad idea <li ng-repeat="person in persons"> {{person.expensiveComputation()}}

    </li> // way better idea <li ng-repeat="person in persons"> {{person.preCalculatedResult}} </li>
  5. Pagination <li ng-repeat="person in persons"> {{person.name}} </li> // better <li

    ng-repeat="person in persons | paginate:page"> {{person.name}} </li> github.com/UnicodeSnowman/angular-paginate-filter
  6. Infinite Scrolling <div infinite-scroll="loadMore()"> <span ng-repeat="person in persons"> {{person.name}} </span>

    </div> $scope.loadMore = function() { var offset = $scope.persons.length; var more = $scope.allPersons.slice(offset, offet+20) $scope.persons = $scope.persons.concat(more); }; // binarymuse.github.io/ngInfiniteScroll/
  7. Cache calculated properties function Collection(els, size) { /* ... */

    } createDynamicProperties(Collection, { view: ['els', 'size', 'page', function () { var offset = this.page * this.size; return this.els.slice(offset, offset.this.size); }] }); <div ng-repeat="person in collection.view"> {{person.name}} </div> github.com/damienklinnert/angular-model
  8. Scalyr Directives <div sly-repeat="person in persons"> {{person.name}} </div> // also

    see sly-evaluate-only-when, // sly-prevent-evaluation-when-hidden github.com/scalyr/angular
  9. Angular Fastscroll <div fastscroll collection="user in users" item-height="40"> <div class="item">{{

    user.name }}</div> </div> // github.com/damienklinnert/fastscroll-demo
  10. Angular+React <table ng-react-component="Repeater" data="data"> </table> var Repeater = React.createClass({ render:

    function () { var scope = this.props.scope; } }); // davidchang.github.io/ngReact/
  11. Where to go from here? (Tooling) — Chrome DevTools —

    Batarang Plugin — angular-instruments github.com/damienklinnert/angular- instruments
  12. Where to go from here? (Reading) — Databinding in AngularJS

    bit.ly/ 1lfMRhj — AngularJS Performance Tuning for Long Lists bit.ly/1tNzbht — Analysing Performance of AngularJS Screens bit.ly/QHRoOc — Brian talks about angular with lots of data bit.ly/RUV6oA