Why is rum/static
not the default?
guess it's just the way it is historically
Yea makes sense. I’m finding that I’m adding static to basically every component to benefit from the efficient immutable prop comparison. I was starting to wonder if there was some downside. It should be pretty simple to copy the defc
macro and customize it to always include the static mixin. Build my own default basically.
Although if I forego the defc macro altogether, and always use plain defn components, does that act like defc < static
?
With React hooks I’ve found that mixins have become less useful
to be fair equality check on immutable data comes with a cost
Fast-path identity check applies good, in most cases, for patterns like re-frame, where there's a central data store / structure, updating the same value means taking advantage of structural sharing, thus identity check short-circuits equality check sooner
But with data created locally in components and passed into child component this is not the case. Creating a hash map from scratch in a component does produce the same value, but equality check has to walk the whole structure, perform deep equality check (value equality), to make sure that those two hash maps are the same.
Now sometimes it may be cheaper to re-run Rum/React component than comparing its arguments and then running it, in case when args didn't change
In case of Rum this might make sense, because most of the Hiccup is pre-compiled, thus running a component doesn't pay perf hit for Hiccup interpretation as much as in Reagent for example.
btw, I think I should put this into Rum's docs.
> to be fair equality check on immutable data comes with a cost
My app does use a top-level state atom (although not re-frame), so the static mixin would still short-circuit to an identical?
check.
Component-local data is indeed different, but I find that those cases are rare and usually the data created is quite small. I hadn’t quite made the mental leap to comparing the speed of arg comparison to the speed of React’s re-render algo (made more interesting by your comment that rum doesn’t suffer hiccup penalties).
put a document in the repo https://github.com/tonsky/rum/blob/gh-pages/doc/optimizations.md
🙏 thanks @roman01la, very helpful and clear