Current state of find vs fetch in templates?

There’s a lot of information of SO pointing out that fetch is much worse than find in a template because of rendering inefficiencies - “fetch will cause everything to rerender whereas a cursor can selectively update the UI.”

Is that actually still true? I seem to remember doing some tests a while back and blaze still handled the updates correctly. What’s the current advice we should be dispensing about this?

I am not shure but I guess Blaze renders arrays well if you provide an _id. As I remember Blaze calls fetch for the cursor. But the current logic could be different

As far as I understand it Blaze is more efficient when rendering cursors rather than arrays. This is because it uses Cursor.observe to determine what what was added, removed, or changed and can then update only the necessary parts of the DOM. When using a fetch the computation is invalidated and a whole new array is returned with no way for blaze to know which data changed. This issue is quite insignificant when you are dealing with small data sets, but not so much if you the data set has hundreds of items.

1 Like

Yeah that was my understanding, but I just did a simple test which shows no rendering difference between the two after each of insert, update, remove to a fetched cursor (the other templates were never removed from the DOM). So I’m inclined to conclude there is no difference from a rendering perspective. Perhaps there’s some corner case I’m not considering.

Found that Blaze.forEach uses observe-sequence that works with diffing arrays by _id field (or index?). So Cursor works as Array for {{# each}}