Is there a way to `remember` something mutable, bu...
# compose
e
Is there a way to
remember
something mutable, but not cause a recomposition when it is mutated?
l
Doesn't
remember {}
do this? If you don't pass it a key it just won't recalculate on recomposition?
e
Yup, my bad. I didn't realize that the Composable was getting called again manually, and not recomposed.
j
This question scares me a little, because it sounds like you are depending on something not recomposing. Compose reserves the right to recompose at any time for any reason at its sole discretion. A Composable function should be a functional transform from input data->UI, so you should not know or care when extra recompositions happen. If an extra recomposition would cause a problem of any kind (other than just the performance/CPU cost of recomposing) then you should rethink your composable.
💯 5
s
@jim I have lazyColumn and on each scroll event I update some state which in turn recompose Composable, But my list scrolling become noticeably slower due to recompose happen every time as i scroll for each item{ }, What could be the efficient way of doing it?
j
@Shakil Karim We are focusing pretty heavily on performance optimizations for the next six-ish months, but it's hard for us to imagine cases that are representative of real-world use cases. If you have a repro of a composition performance issue that is mimetic of some real world code, please do file a bug.
s
Thanks, I will do it.
e
@jim it's a special case for a framework that I'm building. I'm using AnimatedVisibility for top level "container" transitions, and need to keep track of whether the container was previously visible. I'm using
val previousHolder = remember { atomic(holder) }
so I can query the visibility state from the last time the container was updated. I know the correct thing to do is probably to sent the previous state to the composable together with the new state, but it was 2 AM and this was working 😄 The main thing I needed was to not recompose immediately after "remembering" the visibility, because that messed with the animation.