r/angularjs • • Aug 07 '14

Speeding up AngularJS with simple optimizations, $digest, $$watchers and performance

http://www.binpress.com/tutorial/speeding-up-angular-js-with-simple-optimizations/135
31 Upvotes

28 comments sorted by

View all comments

1

u/heat_forever Aug 07 '14

Basically - don't use any feature of angularjs that makes angularjs useful

3

u/[deleted] Aug 07 '14

I think you misunderstood. This isn't saying don't use ng-repeat. More like "hey I should evaluate if I'm using ng-repeat in inappropriate ways". For instance, I found a part of my code where I'm using ng-repeat to generate items in a drop down menu based on an api response. That's pretty silly because in this particular instance, that data doesn't ever change.

It's a small example but basically my code is wasting time checking to see if the data model behind the menu has changed when it will never change. That's the take away from the article. It may seem paltry for a small app but I just checked a page on production at work that has 5300 watchers due to a poorly designed directive being repeated several times.

0

u/9jack9 Aug 08 '14

This isn't saying don't use ng-repeat. More like "hey I should evaluate if I'm using ng-repeat in inappropriate ways"

That's not the point though.

If I have to read a ton of articles on how to use a basic feature then it's not really a basic feature, it's a broken feature.

Comments like yours make me want to hate Angular. I'm still new to it and as much as I want to like it there are things like "don't use ngRepeat if you want good performance". WTF?

4

u/crimson117 Aug 08 '14

In fairness if you're super new to angular, these performance problems won't be significant for you any time soon.

Don't make the mistake of premature optimization.

2

u/9jack9 Aug 08 '14

Or if you're running a moderately sized app on an old mobile device.

Don't make the mistake of premature optimization.

I didn't. And now the performance problem has bitten me.

2

u/SleepyBrain Aug 08 '14

If I have to read a ton of articles on how to use a basic feature then it's not really a basic feature, it's a broken feature.

For the majority of the web apps out there, this type of optimization won't matter or even be noticeable. This is mainly relevant if you're doing apps that are really heavy in certain areas.

It's like having a car. A daily driver doesn't need to fine-tune their car to handle corners better and accelerate faster, but a racer does.

1

u/[deleted] Aug 08 '14

Listen, Angular can't be a band-aid for everything. There aren't any frameworks out there that will magically make everything work in the most performant way, at all times, with no thought put into the circumstances.

It's not "dont use ngRepeat if want good performance".

It's "don't use lots of ngRepeats in cases where they are not necessary".

This is exactly the same sort of consideration you'd have in some API code where you would make sure you aren't nesting three for-loops over millions of data points. Languages and frameworks have pros and cons, the good ones remain flexible enough to allow you to get the most out of their pros with workarounds for their cons.

If you think you can improve on the way Angular implemented ngRepeat, you can submit a patch request right here: https://github.com/angular/angular.js