r/angularjs • • Sep 24 '14

[Resource] Optimizing AngularJS from 1200ms to 35ms

http://blog.scalyr.com/2013/10/angularjs-1200ms-to-35ms/
50 Upvotes

17 comments sorted by

View all comments

2

u/lemon-meringue Sep 25 '14

What's the difference between using optimization #4 and using ng-if? From my experience, correct me if I'm wrong, because ng-if removes the elements, it also removes the watches.

I suppose there may be a slight performance penalty compared to optimization #4 as you have to recreate the DOM nodes, but this should be minor?

1

u/kkeef Sep 25 '14

I don't think that's correct. Ng-if retains watches, I think.

1

u/[deleted] Sep 25 '14

I've used scalyr a while ago and dug a bit in its code. If I'm not mistaking #4 is so the elements remain in the page. With ng-if, they're added/removed and they're also re-compiled when they're re-added. Scalyr is trying to squeeze every bit of caching it can from the browser; it's not made for everyday use, only for those cases when you have a lot of data to render, so at first glance something like this may seem useless but it really comes in handy when you have dozens of thousands of elements to display.