This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-04-19
Channels
- # announcements (24)
- # asami (25)
- # babashka (17)
- # beginners (99)
- # bitcoin (1)
- # calva (2)
- # cider (6)
- # cljs-dev (4)
- # clojure (88)
- # clojure-australia (3)
- # clojure-europe (23)
- # clojure-france (6)
- # clojure-nl (5)
- # clojure-uk (31)
- # clojured (1)
- # clojurescript (6)
- # clojureverse-ops (1)
- # datomic (28)
- # depstar (18)
- # emacs (11)
- # events (1)
- # fulcro (21)
- # graalvm (4)
- # graphql (7)
- # heroku (1)
- # jackdaw (18)
- # joker (3)
- # kaocha (1)
- # lsp (1)
- # malli (13)
- # meander (4)
- # off-topic (12)
- # pathom (14)
- # pedestal (2)
- # podcasts-discuss (1)
- # re-frame (37)
- # reagent (17)
- # reitit (9)
- # shadow-cljs (44)
- # xtdb (17)
@nbtheduke your post here is correct: https://clojurians.slack.com/archives/C0620C0C8/p1618433429119000
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 ran the code with updated deps, and it's certainly faster, but not by much
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