Closed mikef-dk closed 1 year ago
Hi @mikef-dk, thank you for your thoughts ragarding performance improvements.
StateEvent
and StateEventWithContent
are both composable functions. The annotation @Immutable
is targeting classes only. So composables can't be marked as immutable this way. The compose compiler consideres a composable to be skippable
if all passed parameters are immutable and did not change.
I went ahead and marked StateEvent
and StateEventWithContent
explicitly as immutable
. Furthermore I found the @NonRestartableComposable
annotiation which seems fitting for all the event side effect.
After these 2 optimisations, the third parameter action: suspend (T) -> Unit
is the only one that stays unstable
.
I think this is pretty much all the library can optimize at this point.
When using the event side effects, one could try remembering the action
lambda according to this article. If this prevents recompositions strongly depends on the individual implementations of your action
lambda(s).
Compose compiler reports:
stable class Triggered {
}
stable class Consumed {
}
stable class StateEventWithContentTriggered {
runtime val content: T
}
stable class StateEventWithContentConsumed {
}
fun EventEffect(
stable event: StateEvent
stable onConsumed: Function0<Unit>
unstable action: SuspendFunction0<Unit>
)
fun EventEffect(
stable event: StateEventWithContent<T>
stable onConsumed: Function0<Unit>
unstable action: SuspendFunction1<T, Unit>
)
fun NavigationEventEffect(
stable event: StateEvent
stable onConsumed: Function0<Unit>
unstable action: SuspendFunction0<Unit>
)
fun NavigationEventEffect(
stable event: StateEventWithContent<T>
stable onConsumed: Function0<Unit>
unstable action: SuspendFunction1<T, Unit>
)
Hi,
I'm wondering what your thoughts are about marking the
StateEvent
/StateEventWithContent
and its implementation as eitherStable
orImmutable
. I think both are applicable (thoughImmutable
should be more fitting) and would enable theComposables
where those types are used to beskippable
.Any thoughts on this?
As reference: Jetpack Compose Stability Explained