Android TV performance question
I've been testing out the demo on an Android TV box and ran into some performance issues. The program guide is pretty laggy – animations are jerky, and it just doesn't feel responsive, especially considering there aren't many programs in the demo. I have been running release version, so it is not debug build slowness.
I tried to run it on emulator on my Mac and it still feels a bit jerky. However, it runs super smoothly on a Mac with desktopdemo. This makes me wonder if there's something specific with Android and/or animations or if is indeed resource-heavy? Are the plans for performance improvements?
@oleksandrbalan dude, I am also facing this issue. it would be grateful if you solve this issue also , i want to sponsor this library let me know.
Implementation is build on LazyLayout, so it is basically limited by it's performance. When folks from Compose team improve the performance of the LazyLayout, the ProgramGuide will transitively benefit from it.
From my observations the most "heavy" part is a text rendering. So techinally you could try to do some tricks like render text with some delay, as LaunchedEffect works fine in cells.
programs(
// Count of programs
count = ...,
// Necessary layout info of the single program cell
layoutInfo = { ProgramGuideItem.Program(...) }
) {
var renderText by remember { mutableStateOf(false) }
LaunchedEffect(Unit) {
delay(300)
renderText = true
}
if (renderText) {
...
}
}
It is a bit hacky, but could work 🙈
Hi 👋
I use MinaBox for my Android TV program-guide and do not use this repository (programguide). And I have been tuning my use of MinaBox for some time without significant results.
But just something seems wrong on Android TV when navigating with the D-pad. However, my experience is that it has similar performance on Android TV as on mobile when using the mouse - this is possible in the emulator. So what is the actual difference? Does focus with d-pad change the actual rendered element / top level element or the like. When triggers the rendering of elements?
Illustrated with Googles recomposeHighlighter:
Using mouse
Using d-pad
I finally managed to locate a bug in my code and the illustrated behavior above stopped.
I have some suggestions to enhance performance:
- use
rememberas suggested - use
derivedStateOfto avoid unnecessary recompositions - use a
ViewModelto do and keep calculations in memory - cache position information in a hashmap
🚀
can you share sample code so that we can solve the performance issue. @Eightyplus
A bit hard to share the exact improvement since I use MinaBox, but here is an example
val layoutInfos = remember {
mutableMapOf<ProgramInfo, ProgramGuideItem.Program>()
}
fun ProgramInfo.layoutInfo(): ProgramGuideItem.Program {
var layoutInfo = layoutInfos[this]
if (layoutInfo == null) {
layoutInfo = <do you calculations>
layoutInfos[this] = layoutInfo
}
return layoutInfo
}
programs(
// Count of programs
count = ...,
// Necessary layout info of the single program cell
layoutInfo = { it.layoutInfo() }
) {
}
@rahat14 , you can also share your code, then I can come with suggestions 😄
I guess you put all the programs as a list to minabox, consider using androidx-paging3.
Sample: https://github.com/oxyroid/M3UAndroid/blob/25e454045a82c46bf4611e9af51f8b5c10a9c9c4/features/stream/src/main/java/com/m3u/features/stream/components/ProgrammeGuide.kt#L151