Does it matter to Angular if in every digest cycle I return a new list with the same contents vs returning the same list instance? This is assuming default change detection, not OnPush.
1 Answer
It will have some impact - ngFor will need to reevaluate each of the elements - it will do identity check. That should be quick, but if you have thousands elements in a big app it may add some overhead, so if you can it's better to return the same list each time.
-
Thanks. Can you elaborate more on what identity check is? Also, wouldn't it need to reevaluate each element regardless? If I understand correctly, ngFor will cause Angular to keep it's own copy of the list and has to do a deep comparison on every CD.– DandanApr 14, 2017 at 18:16