You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
perf(startup): add baseline and startup profiles for release - #754
Motivation. Release builds shipped no app-specific Baseline Profile, so after install (and before Play cloud profiles arrive, which never happens for GitHub APKs) cold start and the first frames of Compose screens ran interpreted/JIT. This adds a generated Baseline Profile and Startup Profile so ART precompiles the startup path and main-screen hot paths at install time, which reduces startup time and first-interaction jank.
Key implementation points
New :baselineprofile test module (com.android.test + androidx.baselineprofile 1.5.0, which supports AGP 9 without newDsl=false). SDK levels come from build-logic.android.base, which now also handles TestExtension.
BaselineProfileGenerator has two journeys:
startup (includeInStartupProfile = true): first-launch onboarding, then the regular cold start into the main screen.
mainTabs: switches every bottom tab and flings each list. Only goes into the baseline profile so the startup dex stays focused.
StartupBenchmarks compares CompilationMode.None() against Partial(BaselineProfileMode.Require) (cold start, 10 iterations).
:app applies the consumer plugin, adds androidx.profileinstaller (so sideloaded APKs install the profile too), and enables dexLayoutOptimization (R8 orders dex by the startup profile).
Generated profiles are committed under app/src/release/generated/baselineProfiles/. CI does not generate or benchmark; release builds just consume the committed files.
Onboarding bypass: release-derived variants have no test APK that can write DataStore and cannot run-as, so BaselineProfileFixtureReceiver toggles the disclaimer / onboarding flags (and answers the preview theme prompt like the real onboarding finish does). It is exported but guarded by android.permission.DUMP, so only adb shell can call it. It lives in the existing app/src/benchmark source set, which is added to nonMinifiedRelease / benchmarkRelease through the Variant API only.
The plugin-derived variants reuse the existing benchmark build type identity (.benchmark suffix, debug signing, neriplayer-benchmark invite scheme) via a shared useBenchmarkIdentity() helper, so running the generator never overwrites the regular app or its data. The release signing guard skips these two variants; assembleRelease without a keystore is still rejected.
CONTRIBUTING (zh/en) documents how to regenerate and benchmark.
Risks and compatibility
No runtime code change in the shipped release APK besides profileinstaller (its ProfileInstallerInitializer runs through the existing androidx.startup provider, which is merged, not removed). Verified the release APK contains assets/dexopt/baseline.prof, keeps package moe.ouom.neriplayer, and has no fixture class or receiver.
dexLayoutOptimization changes R8 dex ordering for release only.
The committed profile includes 11 rules for BaselineProfileFixtureReceiver. Plugin 1.5.0 applies filter {} only to baseline rules, while startup rules are merged into baseline-prof.txt unfiltered. These classes do not exist in release, so ART ignores them.
Profiles go stale as startup / navigation code changes; regenerate after large changes there (documented).
The committed profiles are 13 MB of text (about 1 MB gzip), and each regeneration adds a similar diff to history.
类型 / Type
Bug 修复 / Bug fix
新功能 / New feature
文档更新 / Documentation update
其他(请描述)/ Other (please describe): performance (startup / jank)
修复或解决的问题 / Issues fixed or closed by this PR
None.
清单 / Checklist
我已阅读并遵循贡献指南 / I have read and followed the contribution guidelines
我已在本地测试这些更改 / I have tested these changes locally
我已运行必要的构建、测试或静态检查 / I have run the required build, tests, or static checks
我已更新相关文档或注释(如适用)/ I have updated relevant documentation or comments (if applicable)
本次更改没有破坏原有行为 / This change does not break existing behavior
本次更改向下兼容(如适用)/ This change is backward compatible (if applicable)
没有提交密钥、Token 或其他敏感信息 / No secrets, tokens, or other sensitive information are committed
UI 变更已附截图或录屏(如适用)/ UI changes include screenshots or recordings (if applicable)
其他信息 / Additional information
How it was tested (emulator Pixel_10_Pro_XL, API 37, arm64):
ANDROID_SERIAL=emulator-5560 ./gradlew :app:generateBaselineProfile: startup and mainTabs pass; 59,084 baseline rules / 51,021 startup rules. Coverage includes onboarding, MainActivity, Explore / Library / Settings tabs, bottom bar, Compose lazy lists, Media3 and OkHttp.
Median −15.6%. Emulator numbers are noisy (one 5.9 s outlier) and only show the trend; real devices usually gain more because the emulator JIT/host differs.
./gradlew :app:assembleRelease -PallowUnsignedRelease=true: compileReleaseArtProfile runs, APK contains assets/dexopt/baseline.prof, no fixture in dex or manifest.
Signing guard dry runs: :app:assembleRelease without keystore still fails; :app:assembleNonMinifiedRelease / :app:assembleBenchmarkRelease pass.
Add a :baselineprofile Macrobenchmark module that generates baseline and
startup profiles for the release build and benchmarks cold start.
- Generator journeys: first-launch onboarding plus regular cold start
(startup profile), and bottom tab switching with list flings
(baseline profile only).
- App consumes the committed profiles, adds profileinstaller and enables
R8 dex layout optimization.
- Plugin-derived nonMinifiedRelease / benchmarkRelease variants reuse the
benchmark identity (.benchmark suffix, debug signing) and the
benchmark source set, which now holds a DUMP-protected receiver that
toggles onboarding state for the generator.
- Release signing guard skips only these two variants.
- Document regeneration and benchmarking in CONTRIBUTING.
It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 4 remain after this review.
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
描述 / Description
Motivation. Release builds shipped no app-specific Baseline Profile, so after install (and before Play cloud profiles arrive, which never happens for GitHub APKs) cold start and the first frames of Compose screens ran interpreted/JIT. This adds a generated Baseline Profile and Startup Profile so ART precompiles the startup path and main-screen hot paths at install time, which reduces startup time and first-interaction jank.
Key implementation points
:baselineprofiletest module (com.android.test+androidx.baselineprofile1.5.0, which supports AGP 9 withoutnewDsl=false). SDK levels come frombuild-logic.android.base, which now also handlesTestExtension.BaselineProfileGeneratorhas two journeys:startup(includeInStartupProfile = true): first-launch onboarding, then the regular cold start into the main screen.mainTabs: switches every bottom tab and flings each list. Only goes into the baseline profile so the startup dex stays focused.StartupBenchmarkscomparesCompilationMode.None()againstPartial(BaselineProfileMode.Require)(cold start, 10 iterations).:appapplies the consumer plugin, addsandroidx.profileinstaller(so sideloaded APKs install the profile too), and enablesdexLayoutOptimization(R8 orders dex by the startup profile).app/src/release/generated/baselineProfiles/. CI does not generate or benchmark; release builds just consume the committed files.run-as, soBaselineProfileFixtureReceivertoggles the disclaimer / onboarding flags (and answers the preview theme prompt like the real onboarding finish does). It is exported but guarded byandroid.permission.DUMP, so onlyadb shellcan call it. It lives in the existingapp/src/benchmarksource set, which is added tononMinifiedRelease/benchmarkReleasethrough the Variant API only.benchmarkbuild type identity (.benchmarksuffix, debug signing,neriplayer-benchmarkinvite scheme) via a shareduseBenchmarkIdentity()helper, so running the generator never overwrites the regular app or its data. The release signing guard skips these two variants;assembleReleasewithout a keystore is still rejected.Risks and compatibility
profileinstaller(itsProfileInstallerInitializerruns through the existingandroidx.startupprovider, which is merged, not removed). Verified the release APK containsassets/dexopt/baseline.prof, keeps packagemoe.ouom.neriplayer, and has no fixture class or receiver.dexLayoutOptimizationchanges R8 dex ordering for release only.BaselineProfileFixtureReceiver. Plugin 1.5.0 appliesfilter {}only to baseline rules, while startup rules are merged intobaseline-prof.txtunfiltered. These classes do not exist in release, so ART ignores them.类型 / Type
修复或解决的问题 / Issues fixed or closed by this PR
None.
清单 / Checklist
其他信息 / Additional information
How it was tested (emulator
Pixel_10_Pro_XL, API 37, arm64):ANDROID_SERIAL=emulator-5560 ./gradlew :app:generateBaselineProfile:startupandmainTabspass; 59,084 baseline rules / 51,021 startup rules. Coverage includes onboarding,MainActivity, Explore / Library / Settings tabs, bottom bar, Compose lazy lists, Media3 and OkHttp../gradlew :baselineprofile:connectedBenchmarkReleaseAndroidTest -Pandroid.testInstrumentationRunnerArguments.androidx.benchmark.suppressErrors=EMULATOR, cold starttimeToInitialDisplayMs, 10 runs each:Median −15.6%. Emulator numbers are noisy (one 5.9 s outlier) and only show the trend; real devices usually gain more because the emulator JIT/host differs.
./gradlew :app:assembleRelease -PallowUnsignedRelease=true:compileReleaseArtProfileruns, APK containsassets/dexopt/baseline.prof, no fixture in dex or manifest.Signing guard dry runs:
:app:assembleReleasewithout keystore still fails;:app:assembleNonMinifiedRelease/:app:assembleBenchmarkReleasepass../gradlew :app:assembleDebug verifyModularization: passed (unit tests, lint, module boundaries, build-logic tests; CRAP16032 scoped methods, 0 > 9).-PenablePerformanceBenchmark=true :app:assembleBenchmark -m: the legacybenchmarkbuild type still configures.Not run:
:app:connectedDebugAndroidTest(no app runtime or UI code changed; CI emulator jobs cover it).No UI change, so no screenshots.
🤖 Generated with Claude Code
本 PR 新增
:baselineprofile模块,并提交生成的 Baseline Profile 与 Startup Profile,用于改善发布版冷启动。baseline.prof,并集成 ProfileInstaller。发布版启用 dex 布局优化。nonMinifiedRelease与benchmarkRelease变体,使用.benchmark包名。发布签名检查不拦截这两个变体。无 keystore 时,assembleRelease仍被拒绝。android.permission.DUMP。timeToInitialDisplayMs从 2908.6 ms 降至 2455.5 ms。CI 不生成 profile,也不运行基准测试。