Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor performance improvement #27

Merged
merged 2 commits into from
Nov 9, 2023
Merged

Conversation

GuhDoy
Copy link
Contributor

@GuhDoy GuhDoy commented Nov 9, 2023

I think this would improve performance at some points while not significantly increasing the complexity of the code. Could you please review my PR? Thanks!

@GuhDoy
Copy link
Contributor Author

GuhDoy commented Nov 9, 2023

Well, I suddenly come up with another idea, which is more capable and simpler.

@nanihadesuka
Copy link
Owner

@GuhDoy thanks for trying improving it but I think current implementation has better UI stability.

Will keep open for a week in case you find a good counter argument 😄

@nanihadesuka nanihadesuka added enhancement New feature or request help wanted Extra attention is needed wontfix This will not be worked on labels Nov 9, 2023
@GuhDoy
Copy link
Contributor Author

GuhDoy commented Nov 9, 2023

I don't think the recomposition you mentioned is possible. I wrote the following shit code to detect the recomposition behavior you mentioned:

        coroutineScope.launch {
            listState.scrollToItem(index = index, scrollOffset = 0)
            val offset = realFirstVisibleItem
                ?.size
                ?.let { it.toFloat() * remainder }
                ?: 0f
            Thread.sleep(100) // Sleep for 0.1 seconds to pretend we're doing something costly.
            val realFirstVisibleItem2 = listState.layoutInfo.visibleItemsInfo.firstOrNull {
                it.index == index
            }
            if (realFirstVisibleItem2 !== realFirstVisibleItem || realFirstVisibleItem2!!.offset != 0) {
                Log.e("TAG", "recomposition") // <-- Log goes here!
            }
            listState.scrollBy(offset)
        }

The log will only be printed when scrolling to the bottom of the LazyColumn.

@nanihadesuka
Copy link
Owner

@GuhDoy ok, tested in real device. Seems there are no apparent issues and test pass. Accepted

@nanihadesuka nanihadesuka merged commit 9896205 into nanihadesuka:master Nov 9, 2023
1 check passed
@nanihadesuka nanihadesuka removed the wontfix This will not be worked on label Nov 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants