Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Is it just me or does ng-repeat DOM inserts not batch. As we all know DOM manipulation is slow and operations should be batched for performance. When using ng-repeat on a collection it should create the DOM elements in memory and then insert them all at once instead of inserting them one at a time.

Is there any advice on how to get this behavior?

share|improve this question
1  
Why do you think they would do it this way (one at a time)? From what I understand the Angular team worked in part with the Chrome team to optimize things, this seems like it would have been done already if it really works best? Do you have a test case? – shaunhusain Jul 9 at 20:16
@shaunhusain I'm not completely sure, it's just what I observed. I see no documentation at all anywhere for batching behavior and I searched a decently long time. I don't think angularjs batches. – Harry Jul 9 at 20:20
   
@shaunhusain unless you're asking for proof on batching being faster? Just look it up on google. – Harry Jul 9 at 20:23
(not asking about batching being faster, meant that it didn't take advantage) So I actually started digging into the code-base myself and I think you're probably right, but I'm not sure how to avoid it: code.angularjs.org/1.1.5/angular.js search for ngRepeatDirective and you'll find the code. – shaunhusain Jul 9 at 20:24
@shaunhusain yep, I also asked on angularjs irc before coming here. github.com/angular/angular.js/blob/master/src/ng/directive/… – Harry Jul 9 at 20:26
show 1 more comment

This question has an open bounty worth +100 reputation from Harry ending in 7 hours.

This question has not received enough attention.

1 Answer

up vote 2 down vote accepted

There is a very good answer about angular's databinding, from one of its creators.

See the comment below, where he explains why angular's dirty-checking approach is better than change listeners:

Change coalescence. Suppose you have an array of items. Say you want to add items into an array, as you are looping to add, each time you add you are firing events on change, which is rendering the UI. This is very bad for performance. What you want is to update the UI only once, at the end. The change events are too fine grained.

In other words, thanks to this dirty-checking approach, angular is already updating DOM in batch.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.