Fork me on GitHub
#membrane
<
2023-09-25
>
zimablue18:09:03

what is ::contextual actually doing differently? the references are in a part I find hard to read in the macros, something like -> don't look in 'default', or 'extra', look in 'context', so that contextuals (just focus?) are available anywhere in the component tree? How does this interact with the caching?

phronmophobic18:09:09

There's a longer answer at https://blog.phronemophobic.com/reusable-ui-components.html But the short answer is that :contextual data is implicitly passed down the whole tree. > How does this interact with the caching? As you might expect, putting lots of data that changes frequently in context is bad for caching. It's best for state that doesn't change frequently. Focus is the most common kind of contextual state, but I think it can make sense for other global state like drag&drop, modals, app-wide styling info, etc.

zimablue18:09:47

so if focus changes, does a component need an explicit reference to that focus to trigger a redraw? or everything redraws?

zimablue18:09:05

thanks for the link, I'll reread it

phronmophobic18:09:11

There's two steps that happens when state changes: 1. Creating a new view 2. Drawing the new view Right now, there's only a few optimizations to save repainting (mostly, because it hasn't been necessary). If the state changes, then it probably triggers both #1 and #2.

phronmophobic18:09:11

Basically, when the state changes, the view function gets called again and the repaint function gets called again.

phronmophobic18:09:45

There's quite a bit of caching done in the view function when using defui components and a little bit of caching done in the repaint function.

zimablue18:09:32

I think my question related to the interaction with the caching of the view function using defui components

zimablue18:09:51

I shouldn't have said redraw, you're right "view" vs "repaint" is the distinction

phronmophobic18:09:13

Yea, there's a cache that memoizes the building of components. Right now, there's not really any special way for a component to say which data it cares about (including contextual data). Part of the problem is that even if a component doesn't care about contextual state, a child component might.

phronmophobic18:09:59

I think there's some really cool optimizations that can be done, but I haven't spent much time on it because it hasn't been a bottleneck for me.

phronmophobic18:09:27

The neat thing is that these optimizations are generic and could be applied to any similar clojure program.

zimablue18:09:29

it's not a bottleneck for me, it's more trying to understand the motivations/constraints for the code

👍 1
zimablue18:09:31

thanks for explaining

phronmophobic18:09:38

Yea, no problem.

phronmophobic19:09:07

I actually wish I could spend more time on these optimization problems because they're interesting, but there's a lot of other work that's probably more impactful.