9blue
9blue

Reputation: 4753

AngularJS dirty checking performance

In the angular scope, I have a huge object scope.a, and somehow I have another scope.b reference to it.

I know angularJS uses dirty checking, so we should reduce the stuff inside scope. My question is, since a and b are essentially the same obj(reference). Will it have noticeable performance improvement if I manage to get rid of b, keep only one reference?

Upvotes: 2

Views: 993

Answers (1)

dnc253
dnc253

Reputation: 40337

Just having something in the scope does not have any performance implications on the $digest cycle (See Integration with the browser event loop here: https://docs.angularjs.org/guide/scope).

The dirty checking ($digest cycle) calls any registered $watch functions (manually registered in your code or registered in the angular code), and then calls the listener function if the $watch function returned anything different from last time.

To answer your question, no there won't be any performance improvement by not adding something to the scope. Performance is most readily improved by improving performance of any $watch functions, since they are always called at least once every $digest cycle.

Upvotes: 1

Related Questions