News for hackers. Stuff that matters.
Re:2 years with Angular by jhpriestley on Monday November 24, 2014 @10:11AM (#8652689)
It is not, in the technical sense, O(n^2). Since it is being performed on a persistent basis, asymptotic analysis is not even quite the right tool to use - there is no single "input" and "output".

What is more precisely true is that the time taken by dirty checking per second scales with d×w×l, where d is the number of digest loops triggered per second, w is the number of watches, and l is the length of the digest cycle (the number of times that the watches are rerun before values stop changing).

Specific applications may find these variables to increase in different ways - all three will generally increase with application size, but for example, adding a digest on mousemove will immediately send d to a very high value.

What I really meant when I said O(N^2) was nothing precise though - just that, when I first read "every time you trigger a digest, we traverse every watch," it sounded like N^2 - it fit the pattern of "for every one of (growing number of things), do each one of (growing number of things)".

Re:2 years with Angular by timruffles on Monday November 24, 2014 @10:19AM (#8652725)
Oh ok, we're agreed. You'll not be having digest loops per second though, that'd be quite a weird situation :)

Digest on mousemove wouldn't be a good idea - look at _.throttle etc. You shouldn't realistically need digest loops more than once per 100ms, as people can't perceive changes happening faster.