feat: integrate Baseline Profiles for performance optimization
- Create a new
:baselineprofilemodule to handle profile generation and benchmarking. - Implement
BaselineProfileGeneratorto capture app startup flows usingBaselineProfileRule. - Implement
StartupBenchmarksusingMacrobenchmarkRuleto measure and verify startup performance improvements. - Configure the
androidx.baselineprofileplugin across the project and link the new module to:cmp-android. - Update dependencies in
libs.versions.tomlto includebenchmark-macro-junit4,uiautomator, andespresso-core. - Register the
:baselineprofilemodule insettings.gradle.kts.
Changes:
- Add baselineprofile module with profile generator and startup benchmarks
- Configure cmp-android to consume baseline profiles
- Enable DEX layout optimization for additional startup gains
- Auto-detect package name via InstrumentationRegistry (generic for template)
Usage: Generate: ./gradlew :cmp-android:generateProdReleaseBaselineProfile Benchmark: ./gradlew :baselineprofile:connectedProdBenchmarkReleaseAndroidTest"
The metrics is calculated after 10 iterations
Without Baseline Profile (CV = 23%): Run 1: 391ms ████████████████████████████████████████ Run 2: 444ms █████████████████████████████████████████████ Run 3: 405ms █████████████████████████████████████████ Run 4: 345ms ███████████████████████████████████ Run 5: 348ms ███████████████████████████████████ Run 6: 241ms ████████████████████████ Run 7: 255ms █████████████████████████ Run 8: 328ms █████████████████████████████████ Run 9: 253ms █████████████████████████ Run 10: 238ms ████████████████████████
With Baseline Profile (CV = 10%): Run 1: 240ms ████████████████████████ Run 2: 278ms ████████████████████████████ Run 3: 306ms ██████████████████████████████ Run 4: 258ms ██████████████████████████ Run 5: 249ms █████████████████████████ Run 6: 224ms ██████████████████████ Run 7: 231ms ███████████████████████ Run 8: 233ms ███████████████████████ Run 9: 240ms ████████████████████████ Run 10: 260ms ██████████████████████████
┌──────────────────────────────────────────────────────────────────┐ │ │ │ 📊 Startup Benchmark Results — Pixel 6a (Android 16) │ │ │ │ ┌────────────────────┬──────────────┬──────────────┬─────────┐ │ │ │ Metric │ No Profile │ With Profile │ Change │ │ │ ├────────────────────┼──────────────┼──────────────┼─────────┤ │ │ │ Median Startup │ 336.34 ms │ 244.74 ms │ -27.2% │ │ │ │ Minimum Startup │ 237.95 ms │ 224.41 ms │ -5.7% │ │ │ │ Maximum Startup │ 444.33 ms │ 306.02 ms │ -31.1% │ │ │ │ Consistency (CV) │ 23.10% │ 9.89% │ 2.3x ⬆️ │ │ │ └────────────────────┴──────────────┴──────────────┴─────────┘ │ │ │ │ No Profile: ████████████████████████████████████ 336ms │ │ With Profile: █████████████████████████ 245ms │ │ ^^^^^^^^^^^ │ │ 91ms SAVED │ │ 27% FASTER │ │ │ └──────────────────────────────────────────────────────────────────┘
Summary by CodeRabbit
-
New Features
- Added baseline profile support to optimize app startup and runtime performance.
-
Chores
- Integrated performance benchmarking infrastructure for monitoring startup performance with and without baseline profile optimizations.
This PR introduces a new baseline profile module to the project for performance measurement and optimization. It adds instrumentation tests for generating baseline profiles and benchmarking startup performance, along with necessary Gradle configuration, dependencies, and manifest setup. 🎯 3 (Moderate) | ⏱️ ~25 minutes 🐰 With baselines drawn and benchmarks run, ✏️ Tip: You can configure your own custom pre-merge checks in the settings.📝 Walkthrough
Walkthrough
Changes
Cohort / File(s)
Summary
New Baseline Profile Module
baselineProfile/.gitignore, baselineProfile/src/main/AndroidManifest.xml, baselineProfile/build.gradle.ktsModule setup with Gradle build configuration, namespace declaration, SDK level targeting, and Android/Kotlin plugin application for baseline profile generation.
Instrumentation Test Classes
baselineProfile/src/main/java/org/mifos/baselineprofile/BaselineProfileGenerator.kt, baselineProfile/src/main/java/org/mifos/baselineprofile/StartupBenchmarks.ktTwo instrumentation test classes:
BaselineProfileGenerator collects startup baseline profiles via BaselineProfileRule, and StartupBenchmarks measures startup performance under different compilation modes using MacrobenchmarkRule with cold-start iterations.
Root Build Configuration
build.gradle.kts, settings.gradle.ktsAdded
baselineprofile plugin to root plugins block and registered :baselineprofile as a new Gradle subproject.
Dependency and Version Management
gradle/libs.versions.toml, cmp-android/build.gradle.ktsDeclared three new library versions (
benchmarkMacroJunit4, uiautomator, espressoCore) and their coordinates, then added baselineProfile project dependency to the main app module.
Build Property Formatting
gradle.propertiesRemoved whitespace around equals sign in
android.testOptions.unitTests.isIncludeAndroidResources property.Estimated code review effort
Poem
Performance measured, tests all done,
Gradle scripts compiled with care,
Startup optimized, metrics fair!
A hopping progress, swift and true. ✨🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name
Status
Explanation
Title check
✅ Passed
The title clearly and specifically describes the main change: integrating Baseline Profiles for performance optimization, which is the core objective of adding the new baselineprofile module and related infrastructure.
Docstring Coverage
✅ Passed
No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check
✅ Passed
Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment @coderabbitai help to get the list of available commands and usage tips.
@markrizkalla It looks like the scope of this PR is limited to Android app only. I think it should be mentioned in the PR title and description.
Edit: I noticed that the description mentions cmp-android.
Are there any metrics related to the optimization and runtime performance that can be showcased here?
Are there any metrics related to the optimization and runtime performance that can be showcased here?
I will provide more details