<@UHAJKUSTU> I am facing this issue, In whatever c...
# decompose
v
@Arkadii Ivanov I am facing this issue, In whatever composable I am passing a function reference of a function inside component, my composable recomposes no matter what Any solution to this Example:
Copy code
FeedPostItem(
    post = it,
    modifier = Modifier.fillMaxWidth(),
    onAction = component::handlePostAction
)
a
Well, you can try
onAction = remember(component) { component::handlePostAction }
. But I strongly advice to avoid premature optimisations, unless you have measuarable performance issues. Re-composition itself doesn't imply re-rendering, and it's usually OK to recompose even on every animation frame. Your composables inside
FreePostItem
should be still skipped if their state has not been changed.
v
Okay that makes sense But I can see my whole lazy column being recomposed, That wont cause any issue, even if the actual ui elements are getting skipped?
Even if it recomposes 20+ times?
a
It shouldn't! Compose is pretty smart. But if you really want to optimise, you can also try the new Strong Skipping Mode introduced in Compose 1.5.4. See the related article: https://medium.com/androiddevelopers/jetpack-compose-strong-skipping-mode-explained-cbdb2aa4b900
v
I already have Strong Skipping Enabled, still all my composables are recomposing due to lambdas
One of my screens have become very heavy and laggy in some devices
d
Are you sure this is not due to your compose function being unstable? There is pattern recommended by google when working with `ViewModel`s. Is this maybe what you are searching for? It recommends using a stateful and stateless composable to avoid recomposition Note: you can think of your component as of viewmodels
👍 1
v
@Djuro I'm already following this, the decompose component is only used in my screen level component and all other child components take the properties and lambda functions
d
is your
post
stable?
Could you check from compose compiler reports? You can find an article on how to get stability report here
v
yup
Post
is stable, all field are
val
and of Stable type
d
I am unsure than, could you provide the evidences from compose compiler reports so we are sue that the lambda is the one that's unstable
v
how to do that?
a
I think
FeedPostItem
can still recompose if the outer (containing) function also recomposes for whatever reason (e.g. if there is
val state by component.state.subscribeAsState()
in there). But the point is that the re-composition should stop quickly somewhere inside
FeedPostItem
- any composables called inside
FeedPostItem
with fully stable and unchanged parameters should be skipped. It might be worth extracting something to separate functions with stable arguments.
☝️ 1
Though, the strong skipping mode is supposed to help!
d
@Vaibhav Jaiswal check out this article. You can skip to “Unstable lambdas” section. Issue you have is probably happening because of lambdas with unstable captures which is coming from your component. Everything is explained well in the article