nowinandroid
nowinandroid copied to clipboard
[Bug]: Extra recompositions
Is there an existing issue for this?
- [X] I have searched the existing issues
Is there a StackOverflow question about this issue?
- [X] I have searched StackOverflow
What happened?
On Interests -> Topics screen
Actual: If you select any item in list, all items on screen will call recomposition.
Expected: Only changed items will call recomposition.
Can you explain what to do with this problem? Thanks
Relevant logcat output
No response
Code of Conduct
- [X] I agree to follow this project's Code of Conduct
I'm guessing the recomposition for the all items happen because the entries of the topics list is recreated every time the follow button is clicked.
@Composable
fun TopicsTabContent(
topics: List<FollowableTopic>,
onTopicClick: (String) -> Unit,
onFollowButtonClick: (String, Boolean) -> Unit,
modifier: Modifier = Modifier
) {
...
I agree that it's an unnecessary recomposition, but it happens one time per the interaction of the button. I believe it doesn't affect the performance that much. What is cared is the large amount of unexpected recompositions.
Objects such as FollowableTopic/Topic that are created in a module in which Compose Compiler does not run, all data classes, even if theoretically immutable, are resolved as unstable.
Also, List<T> is also unstable.

That is probably the cause -- using model classes that don't have stability information + using List directly.
See my PR #664