nowinandroid icon indicating copy to clipboard operation
nowinandroid copied to clipboard

[Bug]: Extra recompositions

Open a-trykashnyi-welltech opened this issue 3 years ago • 2 comments

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

a-trykashnyi-welltech avatar May 30 '22 14:05 a-trykashnyi-welltech

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.

thagikura avatar Sep 13 '22 17:09 thagikura

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.

image

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

Zhuinden avatar Oct 17 '22 01:10 Zhuinden

See my PR #664

hoc081098 avatar Oct 10 '23 04:10 hoc081098