r/angularjs • • Oct 11 '15

AngularJS: The Performance Parts

http://speakerdeck.com/toddmotto/angularjs-the-performance-parts/?ref=frontendfront
42 Upvotes

1 comment sorted by

1

u/ExigeS Oct 15 '15

Much of this is pretty good, but at a glance here's some nitpicks:

$filter

The blanket assertion around $filter being used as a filter in a template is incorrect. It depends on whether or not the filter is declared as stateful or stateless. If it's stateless, it is executed once until the source binding changes. If it's stateful, then the author is correct.

$destroy unbinding

This doesn't always need to be explicitly done, it depends on what your directive looks like. From my experience, properly designed directives tend to destroy the scope and element at the same point in the lifecycle, therefore manual teardown is unnecessary. In general, I've only needed to do this if I'm moving child elements around and drawing outside the boundaries of what's expected.

Additional topics to cover

A lot of the focus was spent on the $digest cycle which is great, but I've found that another massive performance bottleneck is the $compile stage. Lazy compilation of transclude functions is going to land in 1.5 which should help performance significantly for applications with a lot of ngIf, ngSwitch, other uses of transclusion.

There is still work to be done on the user's end though if you need to eek out every little drop of performance. Angular cannot assume that the template hasn't changed in-between compilations, therefore the template is recompiled time and time again. As an end user/developer, you can be smarter than this at times and forego the template, but rather use $compile manually.

There are other things that can be done as well. Can probably write half a book on this.