Dave Scheck
02/01/2023, 8:03 PMSkipped 107 frames! The application may be doing too much work on its main thread.
In this test I have a grid of Text objects that are all fed by the same value. The value is incremented once per second. Everything appears to update on screen properly and without jank, but our meager 1Ghz CPU is sitting at 92-94%. I took out the drawing parts and the app falls down to about 14% CPU.
I've also noticed the layout inspector shows an odd component tree. Is there some compatibility magic going on to make compose work that's increasing the CPU load?
I have tried building up a release build and there isn't much of an improvement there.ViewModel
private val _value = MutableStateFlow(0)
var value = _value.asStateFlow()
private val _isRunning = MutableStateFlow(false)
var isRunning = _isRunning.asStateFlow()
fun start() {
_isRunning.value = true
viewModelScope.launch {
while (_isRunning.value) {
delay(1000)
_value.value++
}
}
}
val screenViewModel: ScreenViewModel = hiltViewModel()
var value = screenViewModel.value.collectAsState().value
Column() {
repeat(5) {
Row(
modifier = Modifier.fillMaxWidth(.95f),
horizontalArrangement = Arrangement.SpaceEvenly,
verticalAlignment = Alignment.CenterVertically
) {
repeat(12) {
Text("$value", style = TextStyle(color = Color.White))
}
}
}
}
romainguy
02/01/2023, 8:21 PMrook
02/01/2023, 8:27 PMDave Scheck
02/01/2023, 8:29 PM@Composable
fun HeavyCpuTestScreen(onBack: () -> Unit) {
val screenViewModel: HeavyCpuTestScreenViewModel = hiltViewModel()
var value = screenViewModel.value.collectAsState().value
var isRunning = screenViewModel.isRunning.collectAsState().value
Column(
modifier = Modifier.background(Color(0xFF000000)),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center
) {
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceEvenly,
verticalAlignment = Alignment.CenterVertically
) {
ActionButton(label = "Stop", enabled = isRunning, onClick = screenViewModel::stop)
ActionButton(label = "Start", enabled = !isRunning, onClick = screenViewModel::start)
}
Column(modifier = Modifier.fillMaxWidth(), verticalArrangement = Arrangement.Bottom) {
repeat(5) {
Row(
modifier = Modifier.fillMaxWidth(.95f),
horizontalArrangement = Arrangement.SpaceEvenly,
verticalAlignment = Alignment.CenterVertically
) {
repeat(12) {
Text("$value", style = TextStyle(color = Color.White))
}
}
}
}
Spacer(modifier = Modifier.height(20.dp))
ActionButton(label = "Exit", onClick = remember {
{
screenViewModel.stop()
onBack()
}
})
}
}
romainguy
02/01/2023, 8:44 PMDave Scheck
02/01/2023, 8:46 PMromainguy
02/01/2023, 10:53 PMDave Scheck
02/01/2023, 11:25 PMromainguy
02/02/2023, 12:07 AMZoltan Demant
02/02/2023, 11:48 AMDave Scheck
02/02/2023, 2:48 PMZoltan Demant
02/02/2023, 2:56 PMDave Scheck
02/02/2023, 3:10 PMvide
02/03/2023, 3:48 PMDave Scheck
02/03/2023, 3:49 PMvide
02/03/2023, 3:49 PMDave Scheck
02/03/2023, 3:50 PMvide
02/03/2023, 3:50 PM1.3.0-alpha03
1.3.0-alpha03
and haven't discovered any other compability issues.Dave Scheck
02/03/2023, 3:56 PMvide
02/03/2023, 3:59 PMDave Scheck
02/03/2023, 4:09 PM