5

My activity loads too slow with Jetpack Compose(about 5 seconds). I have 3 screens with 1 Lazy Vertical Grid and my custom bottom navigation. Does somebody know how to parallel composing this screens or make loading activity faster?

My code:

@ExperimentalAnimationApi
@ExperimentalFoundationApi
@Composable
fun ComposeNavigation() {
    val navController = rememberNavController()
    ConstraintLayout(modifier = Modifier.fillMaxSize()) {
        val (content, bottomSheet) = createRefs()
        //Bottom is my custom bottom navigation
        Bottom(navController, modifier = Modifier
            .constrainAs(bottomSheet) {
                start.linkTo(parent.start)
                end.linkTo(parent.end)
                bottom.linkTo(parent.bottom)
            }
            .fillMaxWidth())
        Box(modifier = Modifier
            .fillMaxWidth()
            .constrainAs(content) {
                start.linkTo(parent.start)
                end.linkTo(parent.end)
            }) {
            NavHost(
                navController = navController,
                startDestination = "first_screen",
            ) {
                composable("first_screen") {
                    FirstScreen(navController = navController)
                }
                composable("second_screen") {
                    SecondScreen(navController = navController)
                }
                composable("third_screen") {
                    ThirdScreen(navController = navController)
                }
            }
        }
    }
}
Renattele Renattele
  • 1,626
  • 2
  • 15
  • 32
  • I'd probably suggest taking things out one by one to see whats causing the slow load. Most likely there's some slow logic happening somewhere. Compose on its own is pretty fast. On a side point, you could get rid of constraint layout and just use boxes in your sample, constraint layout doesn't give any performance benefit in compose world. – enyciaa Mar 24 '21 at 21:16
  • 1
    @enyciaa, I removed ConstraintLayout(changed to column) but activity loads too slow. Note: on emulator loading activity is perfect but on my real device with Snapdragon 425 is too slow. – Renattele Renattele Mar 25 '21 at 10:54
  • 1
    It is my case too, I have very simple Composable, on Huawei P20 Pro - takes a few seconds to display the "Hello World"... – Jiří Křivánek Oct 27 '21 at 22:00

1 Answers1

2

Look for rendering bottlenecks in your XScreen views.

One of my mistake, that dramatically slowed rendering performance was the library i used to imitate neu shadows https://github.com/CuriousNikhil/neumorphic-compose. After removing all of this effects the App took off like a rocket.

  • Just run your app with Android Studio profiler https://developer.android.com/studio/profile/android-profiler (the only thing, that helped me to find bottleneck).

  • Other possible confuse - if you are investigating performance on Debug build variant. Try to run Release one. This is my Release config (pay attention to Proguard (actually R8) file ):

    buildTypes {
        release {
            isMinifyEnabled = true
            isShrinkResources = true

            proguardFiles(
                getDefaultProguardFile("proguard-android.txt"),
                "proguard-rules.pro"
            )

            signingConfig = signingConfigs.getByName("release")
        }
    }
  • The last one to notice is that ART improves the thing further when your App is installed from Play Store as a bundle.
uptoyou
  • 1,427
  • 19
  • 24