Replies: 4 comments 9 replies
-
Hi @fabstu, thanks for experimenting with this! Could you push a branch that has these changes so that it's easy for others to poke around? |
Beta Was this translation helpful? Give feedback.
-
Hey @fabstu! Sorry, I misread your intent when you proposed the idea in the closed PR. This is indeed related to something with which I've experimented in the past. In one case, I was building the list of accessed properties as you did (but I was only keeping track of the My main concern is performance, as storing and rehydrating a collection of |
Beta Was this translation helpful? Give feedback.
-
Haha, I went and wrote a very similar thing last night after our discussion. Also tried some concepts where you manually specify what you want to observe: let titleStore = store.observe(\.title) EDIT: I've moved the the rest, a proposal for an alternative solution, to a separate thread (#1454), so as to not hijack this one. |
Beta Was this translation helpful? Give feedback.
-
I think this is very cool, and as I said I explored similar things myself, but I just want to clarify, this would only be for debug builds, right? At least I personally don't think we should have all this magic in release builds, I think we should trust people to know what they're doing if they get that far. But for debug builds, I do feel that this is a better way to nudge people than making |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Here I already mentioned my foolish idea to try to track what values get accessed inside a WithViewStore closure run.
Its pretty easy to detect what gets accessed through the subscript on the ViewStore, as long as .state is not used directly.Correction: its not as simple to track what is being accessed as I thought.
Proof of concept
Anyway, here is a small proof-of-concept. It avoids re-running the closure as long as only equatables changed, but re-runs when any non-equatable changed (didn't test the second part).
Branch (based on protocol-beta): https://github.com/fabstu/swift-composable-architecture/tree/exp-tracking-changes
Added the example as the first case study "Smart View Store".
Commits: protocol-beta...fabstu:swift-composable-architecture:exp-tracking-changes
Tracking:
Hacked in
Still missing:
Limitations
.tabs.count
tracks changes to any tab in.tabs
instead of just a changed count (Int)..state
and similar ways without going through dynamic member lookup means any variable of state could have been accessed, requiring a re-run without any tracking gains while the overhead from the dynamic member lookup still exists (can be optimized?).Note: This is just an inspiration. Did you guys try something like this already? If so, I'm just wondering what came of it.
Open questions
@Binding
or some such places should be re-run?objectWillChange.send()
calls in other placesBeta Was this translation helpful? Give feedback.
All reactions