I’ve hit quite a serious performance issue in an app I’ve been building. In a nutshell, I have an array of complex objects. I loop through the array with #each and a series of nested components renders these complex objects. There are a lot of them…
I may modify the properties on one of these objects, add one, remove one or move one to a different location in the array. In each case, I’d expect Ember to have to re-render (or more specifically, re-process) the one that has changed and leave the rest as they were. But this is not what I am seeing. Instead every object is being re-processed. This is causing huge performance problems for me.
{{#each data as |item|}}
{{my-component item=item}}
{{/each}}
To be more specific, the components are not all re-rendering. If, in my-component I have this {{item.label}} then that seems to be ok. But, if I have {{computedProperty}} and a function:
computedProperty : function()
{
var item=this.get("item");
return item.label;
}.property('item.label')
…then every time I add an item to the data array (using pushObject), this function gets fired to re-calculate the label for every item in the array, not just the new one. If I update the label property for a single item in the data array, then, as expected, this function only get fired for the one item that had its label changed.
The same is true if I do something like this:
computedProperty : null,
x : function()
{
var item=this.get("item");
This.set("computedProperty",item.label);
}.observes('item.label')
So my question is, what do I need to do differently to prevent these functions firing when not needed? In my case these functions so some pretty complex processing, so having that redone each time I make a change to a single object is killing the app.
By that way, I’m using Ember-CLI v1.13.1 for my app.