Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Take advantage of Baseline Profile to Improve y...

Eric Ampire
December 17, 2022

Take advantage of Baseline Profile to Improve your app Performance

Eric Ampire

December 17, 2022
Tweet

Other Decks in Programming

Transcript

  1. Take advantage of Baseline Profile to Improve your app Performance

    Eric Ampire Senior Mobile Dev at Lottiefiles - GDE Android @eric_ampire
  2. Understanding Key concept • How Jetpack Compose Vs View System

    are distributed • Compilation behavior
  3. Understanding Key concept • How Jetpack Compose Vs View System

    are distributed • Compilation behavior • What’s the baseline profiler
  4. Understanding Key concept • How Jetpack Compose Vs View System

    are distributed • Compilation behavior • What’s the baseline profiler • What’s the advantage of the baseline profiler
  5. Understanding Key concept • How Jetpack Compose Vs View System

    are distributed • Compilation behavior • What’s the baseline profiler • What’s the advantage of the baseline profiler • How to generate a baseline profiler
  6. Understanding Key concept • How Jetpack Compose Vs View System

    are distributed • Compilation behavior • What’s the baseline profiler • What’s the advantage of the baseline profiler • How to generate a baseline profiler • Measure the app performance after using the baseline profiler
  7. How Jetpack Compose Vs View System are distributed • Unbundle

    • Compose can be update independently from any specific version of Androïd
  8. How Jetpack Compose Vs View System are distributed • Unbundle

    • Compose can be update independently from any specific version of Androïd • Devices running old version of Android can easily used last compose feature
  9. How Jetpack Compose Vs View System are distributed • A

    library need to be loaded • Need to be interpreted when a feature is needed
  10. How Jetpack Compose Vs View System are distributed • A

    library need to be loaded • Need to be interpreted when a feature is needed • The view system is part of the Android system and no need to be compiled before being used
  11. Compilation Behavior • Initial Performance (After the app installation, after

    process cold start) : Slow Android 1.0 : Interpreted only
  12. Compilation Behavior • Initial Performance (After the app installation, after

    process cold start) : Slow • Eventual Performance (After the runtime): Slow Android 1.0 : Interpreted only
  13. Compilation Behavior • Initial Performance (After the app installation, after

    process cold start) : Slow • Eventual Performance (After the runtime): Slow • Disk Size (No optimization) : Small Android 1.0 : Interpreted only
  14. Compilation Behavior • Initial Performance (After the app installation, after

    process cold start) : Slow Android 2.2 Froyo : Interpreted + JIT
  15. Compilation Behavior • Initial Performance (After the app installation, after

    process cold start) : Slow • Eventual Performance (After the runtime) : Fast - The JIT will discover hot part and optimized them - Those optimization will disappear when the process died Android 2.2 Froyo : Interpreted + JIT
  16. Compilation Behavior • Initial Performance (After the app installation, after

    process cold start) : Slow • Eventual Performance (After the runtime) : Fast - The JIT will discover hot part and optimized them - Those optimization will disappear when the process died • Disk Size (Optimization disappear when the process died) : Small Android 2.2 Froyo : Interpreted + JIT
  17. Compilation Behavior • Initial Performance (After the app installation, after

    process cold start) : Fast Android 5 Lollipop : Full AOT (Ahead of Time Compilation)
  18. Compilation Behavior • Initial Performance (After the app installation, after

    process cold start) : Fast • Eventual Performance (After the runtime) : Fast Android 5 Lollipop : Full AOT (Ahead of Time Compilation)
  19. Compilation Behavior • Initial Performance (After the app installation, after

    process cold start) : Fast • Eventual Performance (After the runtime) : Fast • Disk Size (Lot of optimizations) : Large Android 5 Lollipop : Full AOT (Ahead of Time Compilation)
  20. Compilation Behavior • Initial Performance (not compiling the all apk)

    : Fast / Slow • Eventual Performance (After the runtime) : Fast Android 7 : JIT + PGO
  21. Compilation Behavior • Initial Performance (not compiling the all apk)

    : Fast / Slow • Eventual Performance (After the runtime) : Fast • Disk Size (Few optimizations) : Small Android 7 : JIT + PGO
  22. Compilation Behavior • Initial Performance (not compiling the all apk,

    but can depend) : Fast • Eventual Performance (After the runtime) : Fast Android 9+ : Cloud Profiles
  23. Compilation Behavior • Initial Performance (not compiling the all apk,

    but can depend) : Fast • Eventual Performance (After the runtime) : Fast • Disk Size (Few optimizations) : Small Android 9+ : Cloud Profiles
  24. Baseline Profiles App or Libraries • It can be included

    in libraries to optimize performance for all its consumers
  25. Generate Baseline Profiles Jetpack Macrobenchmark Library class BaselineProfileGenerator { @get:Rule

    val baselineProfileRule = BaselineProfileRule() @Test fun generate() {} }
  26. Generate Baseline Profiles Jetpack Macrobenchmark Library class BaselineProfileGenerator { @get:Rule

    val baselineProfileRule = BaselineProfileRule() @Test fun generate() { baselineProfileRule.collectBaselineProfile() } }
  27. Generate Baseline Profiles Jetpack Macrobenchmark Library @Test fun generate() {

    baselineProfileRule.collectBaselineProfile( packageName = "com.example", profileBlock = { this: MacrobenchmarkScope } ) }
  28. Generate Baseline Profiles Jetpack Macrobenchmark Library profileBlock = { this:

    MacrobenchmarkScope :/ a. Most important aspect :/ b. Thinks that worth optimisation }
  29. Generate Baseline Profiles Jetpack Macrobenchmark Library profileBlock = { //

    Start the activity and wait until // The first frame of your activity is rendered startActivityAndWait() }
  30. Generate Baseline Profiles Jetpack Macrobenchmark Library profileBlock = { //

    Start the activity and wait until // The first frame of your activity is rendered startActivityAndWait() device.wait(Until.hasObject(By.res("feed")), 5000) }
  31. Generate Baseline Profiles Jetpack Macrobenchmark Library profileBlock = { //

    Start the activity and wait until // The first frame of your activity is rendered startActivityAndWait() device.wait(Until.hasObject(By.res("feed")), 5000) val feed = device.findObject(By.res("feed")) }
  32. Generate Baseline Profiles Jetpack Macrobenchmark Library profileBlock = { //

    Start the activity and wait until // The first frame of your activity is rendered startActivityAndWait() device.wait(Until.hasObject(By.res("feed")), 5000) val feed = device.findObject(By.res("feed")) feed.fling.(Direction.DOWN) }
  33. Baseline Profiles • If you are using a library with

    baseline profiles, it’ll be merged by the one from the application
  34. Baseline Profiles • If you are using a library with

    baseline profiles, it’ll be merged by the one from the application • Upload it to the playstore so other applications can take advantage of it
  35. Baseline Profiles • If you are using a library with

    baseline profiles, it’ll be merged by the one from the application • Upload it to the playstore so other applications can take advantage of it. • It can be distributed
  36. Baseline Profiles • If you are using a library with

    baseline profiles, it’ll be merged by the one from the application • Upload it to the playstore so other applications can take advantage of it. • It can be distributed
  37. Measure the app performance • Google Play Vitals • Firebase

    Performance Monitoring • Jetpack Macrobenchmark
  38. Measure the app performance @RunWith(AndroidJunit4ClassRunner::class) class StartupBenchmarks { @get:Rule val

    benchmarkRule = MacrobenchmarkRule() private fun startup() = benchmarkRule.measureRepeated( packageName = "com.example", metrics = listOf(StartupTimingMetric()), iterations = 10, measureBlock = {} ) }
  39. Measure the app performance measureBlock = { pressHome() startActivityAndWait() device.wait(Until.hasObject(By.res("feed")),

    5000) val feed = device.findObject(By.res("feed")) feed.fling.(Direction.DOWN) }
  40. Measure the app performance measureBlock = { pressHome() startActivityAndWait() device.wait(Until.hasObject(By.res("feed")),

    5000) val feed = device.findObject(By.res("feed")) feed.fling.(Direction.DOWN) }
  41. Measure the app performance @RunWith(AndroidJunit4ClassRunner::class) class StartupBenchmarks { @Test fun

    startupNoCompilation() = startup(CompilationMode.None()) @Test fun startupBaselineProfile() = startup(CompilationMode.Partial()) }