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

RecompositionMode.Immediate with a non-main dispatcher cause ANR while scrolling a LazyColumn (Android) #396

Closed
j2esu opened this issue Mar 6, 2024 · 5 comments
Labels
bug Something isn't working

Comments

@j2esu
Copy link

j2esu commented Mar 6, 2024

According to the docs RecompositionMode.Immediate can be used "for running molecules off the main thread".
When I try to use it with any non-main dispatchers (tried Default, IO, new single thread dispatcher) my app freezes and then gives ANR when I scroll any LazyColumn.
I don't even use the result of molecule to render the list, just any call to molecule affects lazy lists that way.
Please let me know if I'm doing something wrong.

Molecule 1.4.1
Compose compiler 1.5.10
Compose UI 1.6.2
Android SDK 34

MRE:

class MainActivity : ComponentActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        lifecycleScope.launchMolecule(RecompositionMode.Immediate, Dispatchers.Default) { }
        setContent {
            LazyColumn(modifier = Modifier.fillMaxSize()) {
                items(100) {
                    Text(text = "Item $it", modifier = Modifier.padding(16.dp))
                }
            }
        }
    }
}
@JakeWharton
Copy link
Collaborator

Yeah I suspect this is due to the snapshot system and both us and Compose UI launching a coroutine to apply snapshots periodically, but would have to confirm that. It also means that we likely can reproduce this in pure Compose (i.e., no Molecule) and potentially file a bug upstream.

@JakeWharton JakeWharton added the bug Something isn't working label Mar 6, 2024
@JakeWharton
Copy link
Collaborator

I do not have time to look at this any time soon. If no one else does, I'll get to it eventually.

@jingibus
Copy link
Contributor

This has also hit us pretty hard at Cash. We're raising the issue with upstream.

@JakeWharton
Copy link
Collaborator

JakeWharton commented Mar 11, 2024

It also means that we likely can reproduce this in pure Compose (i.e., no Molecule) and potentially file a bug upstream.

https://issuetracker.google.com/issues/329011032

@j2esu
Copy link
Author

j2esu commented Apr 4, 2024

Tested with androidx.compose.runtime:runtime:1.7.0-alpha06. Looks fixed to me, no more ANRs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants