I'm geting a lot of undesired recompositions and I...
# compose
p
I'm geting a lot of undesired recompositions and I'm trying to figure out why. I have a big uistate with various data, stored on a stateflow which is passed down to some composables to paint data depending on some values
Copy code
data class mapState(
    val hasLocationPermission: Boolean = false,
    val userLocation: LatLng? = null,
    val loadingArrivalTimes: Boolean = false,
    val busStops: List<BusStop> = emptyList(),
    [...various data more...]
)
private val _mapState = MutableStateFlow(MapState())
val mapState: StateFlow<MapState> = _mapState
If I change something on for example "busStops" using update/copy on _uiState... will every composable in which the full mapState object is passed be recomposed even if other variables are used and not "busStops"? if so, which is the recommended approach to avoid this?
d
Yes, changes in composable function's parameter will cause recomposition. Typically you should only add just the necessary parameters to composable functions, instead of passing one or two bigger objects. This should help avoid unnecessary recompositions.
m
Also if you are not using strong skipping mode, than the
busStops
list is not considered immutable and functions taking in
mapState
are not skippable. But the general way to reduce things are to have the function that uses the whole state object delegate to other composable functions that take less of the state. Then those functions can be skipped if they don't use the part of the state that changed.
p
@Michael Krussel I don't understand that strong skipping mode explanation, can you expand it?