Repository navigation
Conversation
… a cache and hide DOM elements associated to filtered out object of the collection. Make it faster to display again those element when filtered in.
|
Could you not simply remove the filter altogether and add a ng-hide directive to your items that will be repeated? where filterOut would return true if this item is to be hidden. |
|
Thanks Peter for the suggestion. The thing is my items collection is coming from a service and used in several places. It is filtered in the service for that reason (I used to filter in the template, but I had to do it at several places so it was not DRY nor efficient). Here is a simplified real example (without the keepCache patch): http://plnkr.co/edit/APkF1r1aM3NNHx9R8S6e?p=preview With your solution, it means I need to maintain a collection unfiltered to put in this ngRepeat, and another one filtered for other uses, and call the filtering function twice (in the service for the filtered collection + in the ngHide on the ngRepeart node, the later could be call several time per $digest) Something like : http://plnkr.co/edit/3tUfHwvGiQMp6pdDou8D?p=preview I will try your suggestion in my real app (where creating the ng-repeat node is quite expensive), but it will still be less efficient. |
|
@jmaynier My main concern with this change is that it would lead to potential memory leaks. How would one clear the cache at a later stage? |
|
I tried in my real app your suggestion (based on the idea demoed in http://plnkr.co/edit/3tUfHwvGiQMp6pdDou8D?p=preview). I used the unfiltered list in the ngRepeat with ng-hide + filter and the filtered one everywhere else. Their is no perceptible performance difference between my hack on ngRepeat and your solution (around 1-2 seconds to filter/display list, more than 5 seconds with the raw ngRepeat on the filtered list). So I can stay with that solution and close the PR. What will be perfect would be a virtual scroll solution for ngRepeat (using ng-grid is not ideal as I want to display a feed, with 2 ngRepeat nested, not data in row). So memory print would be lower and time to display faster. Do you know if it will be build into ngRepear in the near future ? |
|
Thanks for coming back on this. I will close for now. |
|
Thks again Peter for your help. I will see how I can integrate virtual scrolling in a fork of ngRepeat. |
Add keepCache parameter to have the option to keep in a cache and hide DOM elements associated to filtered out object of the collection. Make it faster to display again those element when filtered in.
For a large collection, it is sometimes very slow for angular to recreate all DOM node that were filtered out and are now filtered in. This prevent the deletion of those DOM nodes and keep them in a cache.
Usage: