Fork me on GitHub
#reagent
<
2021-04-19
>
lilactown15:04:09

I don't know what your question is, though

lilactown15:04:15

why what happens?

Noah Bogart16:04:16

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?

Noah Bogart16:04:41

I would expect that creating the cursor at the top level is the only way to avoid rerendering but that’s not the case

athomasoriginal17:04:34

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.

athomasoriginal17:04:04

Having said this, if you have 1 flat component and use a cursor this by itself doesn’t make the rendering more performant.

athomasoriginal17:04:37

You would have to strategically use cursors in some components and not others and possibly at different levels of nesting.

Noah Bogart17:04:05

interesting, thank you

lilactown20:04:13

I'm not convinced that the examples in that article are correct

Noah Bogart20:04:33

i ran the code with updated deps, and it's certainly faster, but not by much

lilactown20:04:47

you're right to be suspicious of that snippet you pasted.

lilactown20:04:41

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

lilactown20:04:56

which is ostensibly what the player cursor is trying to avoid

lilactown20:04:49

the reason they saw any perf benefits at all was due to the game cursor removing the dependency on the full games ratom

lilactown20:04:05

so you can update game 1 and it won't re-render the component depending on game 38

lilactown20:04:15

but if you change any player in game 38, it will re-render the entire list of players