If I use `mutableStateOf` by default the `structur...
# compose
e
If I use
mutableStateOf
by default the
structuralEqualityPolicy
is used to find changes. But what policy is used for parameters passed to the Composable function? Are they compared by value of by reference?
c
No. Composable functions compare mutable state objects by reference. The
structuralEqualityPolicy
affects whether the state is considered modified when a new value is assigned to it. Assigning a new value to a state will cause it to eventually be sent to all snapshot apply listeners which, the
Recomposer
being one, will invalidate the parts of the composition (if any) that read the state object and schedule the composition to be recomposed (hence the name).
s
When comparing parameters for skipping, Compose uses
==
for stable parameters and
===
for function references (because their equals implementation is weird). With strong skipping, Compose uses
===
for unstable parameters, making more functions skippable.
e
@shikasd What it depends on if the parameter is stable or not?
@Chuck Jazdzewski [G] Yes, I was talking about this:
If the value of the mutable state is changed by default it is compared with the old value by
==
to decide if recomposition is needed, right? My question was how changes in the function parameters are checked.
s
e
Thanks a lot!
@shikasd Does it make any sense to mark data classes with all `val`s as
Immutable
?
s
Not really, unless you see some performance issues with the function it is used in and determine that it is caused by the function being not skippable
👍 1
124 Views