programguide icon indicating copy to clipboard operation
programguide copied to clipboard

Android TV performance question

Open jfayz opened this issue 2 years ago • 8 comments

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?

jfayz avatar Nov 28 '23 07:11 jfayz

@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.

rahat14 avatar Dec 01 '23 11:12 rahat14

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 🙈

oleksandrbalan avatar Dec 04 '23 18:12 oleksandrbalan

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 Screenshot_1703070836

Using d-pad Screenshot_1703070845

Eightyplus avatar Dec 20 '23 11:12 Eightyplus

I finally managed to locate a bug in my code and the illustrated behavior above stopped.

I have some suggestions to enhance performance:

  1. use remember as suggested
  2. use derivedStateOf to avoid unnecessary recompositions
  3. use a ViewModel to do and keep calculations in memory
  4. cache position information in a hashmap

🚀

Eightyplus avatar Jan 03 '24 09:01 Eightyplus

can you share sample code so that we can solve the performance issue. @Eightyplus

rahat14 avatar Jan 03 '24 09:01 rahat14

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() }
    ) {

    }

Eightyplus avatar Jan 03 '24 09:01 Eightyplus

@rahat14 , you can also share your code, then I can come with suggestions 😄

Eightyplus avatar Jan 08 '24 13:01 Eightyplus

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

oxyroid avatar May 11 '24 18:05 oxyroid