eygraber
07/26/2021, 5:24 PMFlow<SomeState>
with collectAsState
instead of multiple MutableState
and will rely on function skipping if the discrete fields in SomeState
haven't changed (SomeState
will be immutable).
<\tl;dr>
(longer description in thread)collectAsState
from the UI state flow, and deconstruct it, passing the discrete state to multiple nested composables, to take advantage of the skipping aspect of compose (because it's unlikely that all state fields will mutate at the same time).
My main concern is that I could run into performance issues, since this isn't really using the snapshot system. Is this a bad idea, and if not, what are some potential pitfalls to watch out for?Zach Klippenstein (he/him) [MOD]
07/26/2021, 6:36 PMSomeState
is deeply immutable, which I assume you were already doing.
If your collectAsState is relatively high in your composable tree, then if something in the leaf of your state tree changes you’ll be recomposing a little more than if everything were mutable states, but compose should still mostly only recompose the path down the tree that leads to what actually changed, and I’m guessing most of those composables would be simpler layout definitions and stuff that won’t be that expensive.eygraber
07/26/2021, 6:52 PMZach Klippenstein (he/him) [MOD]
07/26/2021, 7:56 PMeygraber
07/26/2021, 8:17 PMcollectAsState
but I can't find it now (maybe after clarification the comment was deleted?)Adam Powell
07/26/2021, 8:48 PMinitial = MovieDetailState()
in the collectAsState
call - better to use a constant than construct a new default/empty one every recomposition just to pass it as an initial value that will be ignored after the first time 🙂eygraber
07/26/2021, 10:33 PMNathan Castlehow
07/27/2021, 1:27 AMeygraber
07/27/2021, 4:11 AM