Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJS really slow at rendering with about 2000 elements?

Here's the fiddle: http://jsfiddle.net/D5h7H/7/

It renders the following:

<div ng-repeat="group in Model.Groups">     <span>{{group.Name}}</span>     <div ng-repeat="filter in group.Filters">         <input type="checkbox" ng-model="filter.enabled">{{filter.Name}}         <select ng-disabled="!filter.enabled">             <option ng-repeat="value in filter.Values">{{value}}</option>         </select>     </div> </div> 

It's a list of filters that is loaded in json from the server and then rendered to the user (in an example json is generated right there in Fiddle). At the moment there are 6 groups of 30 filters in each with 15 option elements for each filter.

In Firefox it now takes about 2 seconds to redraw the UI.

Is this time ok for angular js? Is there anything I'm doing wrong that caused 2sec. rendering (cause 2000 elements doesn't look as a big number to me, but 2sec. is certainly big)?

like image 843
Shaddix Avatar asked Mar 03 '13 06:03

Shaddix


People also ask

Why AngularJS is slow?

Usually, if your app is becoming slow, the main reason for it is too many watchers. AngularJS uses dirty checking to keep track of all the changes made in the code. If two watchers are interlinked, the digest cycle runs twice to ensure that all the data is updated.


1 Answers

In AngularJS 1.3+, there is One-time binding built-in:

The main purpose of one-time binding expression is to provide a way to create a binding that gets deregistered and frees up resources once the binding is stabilized. Reducing the number of expressions being watched makes the digest loop faster and allows more information to be displayed at the same time.

In order to make the one-time binding, prepend :: to the binding value:

<div>{{::name}}</div>  

Also see relevant discussions:

  • Render value without data-binding
  • How does data binding work in AngularJS?
  • Genuinely stop a element from binding - unbind an element - AngularJS
like image 68
alecxe Avatar answered Sep 23 '22 13:09

alecxe