@nbtheduke your post here is correct: https://clojurians.slack.com/archives/C0620C0C8/p1618433429119000
I don't know what your question is, though
why what happens?
Why does creating a cursor inside of the function provide such a speed up? If passing game in is the issue (because every time it changes everything as to rerender), why doesn’t the rerendering slowdown happen inside of this function too?
I would expect that creating the cursor at the top level is the only way to avoid rerendering but that’s not the case
I believe what is being highlighted is that if your component(s) are listening for a change to any key in the atom
this will trigger re-renders at a higher frequency because your component might only care about :a
, but :b
was updated and now the whole component re-renders
However, if you use a cursor
your components will only re-render when the specific key in the cursor has changed. The result is that you get less re-renders because you’re only listening for changes to specific keys in the atom, not any key.
Having said this, if you have 1 flat component and use a cursor this by itself doesn’t make the rendering more performant.
You would have to strategically use cursors in some components and not others and possibly at different levels of nesting.
interesting, thank you
I'm not convinced that the examples in that article are correct
i ran the code with updated deps, and it's certainly faster, but not by much
you're right to be suspicious of that snippet you pasted.
the issue isn't reconstructing the cursor every time, but the fact that you don't save anything by using cursors in this case because every time the game
cursor re-renders, the player-component
will re-render regardless
which is ostensibly what the player
cursor is trying to avoid
the reason they saw any perf benefits at all was due to the game
cursor removing the dependency on the full games
ratom
so you can update game 1 and it won't re-render the component depending on game 38
but if you change any player in game 38, it will re-render the entire list of players