Skip to content

perf(startup): add baseline and startup profiles for release - #754

Merged
cwuom merged 2 commits into
masterfrom
perf/baseline-profile
Nov 28, 2026
Merged

cwuom merged 2 commits into
masterfrom
perf/baseline-profile

Conversation

@cwuom

@cwuom cwuom commented Nov 28, 2026 •

Copy link
Copy Markdown
Owner

描述 / 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

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

  • ./gradlew :baselineprofile:connectedBenchmarkReleaseAndroidTest -Pandroid.testInstrumentationRunnerArguments.androidx.benchmark.suppressErrors=EMULATOR, cold start timeToInitialDisplayMs, 10 runs each:

    Compilation min median max
    None 2545.5 2908.6 3908.4
    Baseline Profile (Require) 1839.1 2455.5 5889.1

    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.

  • ./gradlew :app:assembleDebug verifyModularization: passed (unit tests, lint, module boundaries, build-logic tests; CRAP 16032 scoped methods, 0 > 9).

  • -PenablePerformanceBenchmark=true :app:assembleBenchmark -m: the legacy benchmark build 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 仍被拒绝。
  • 广播接收器仅包含在 benchmark 类变体中,且需要 android.permission.DUMP。
  • 作者报告模拟器中位 timeToInitialDisplayMs 从 2908.6 ms 降至 2455.5 ms。CI 不生成 profile,也不运行基准测试。

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.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 28, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-28T10:12:08.981232Z 9bca9f8 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

Explain Change →

Note

Reviews paused

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.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • Resume reviews
  • Trigger review

No actionable comments were generated in the recent review.

Walkthrough

新增 Baseline Profile 测试模块和应用 benchmark 变体。新增 fixture 接收器,用于设置 onboarding 状态。基线配置文件测试覆盖启动和主标签页路径。启动基准测试测量两种编译模式下的冷启动耗时。

Merge Risk: Minimal · up to 89292 · assessed changes only

Path filters excluded changed files. This rating applies only to the assessed changes.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed 标题“perf(startup): add baseline and startup profiles for release”准确概括了本 PR 的主要变更:新增 Baseline Profile 与 Startup Profile 生成模块、启动基准测试、profile 安装器,并启用 release 的 dex 布局优化。变更摘要中的 :baselineprofile 模块、Baseline…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

标题“perf(startup): add baseline and startup profiles for release”准确概括了本 PR 的主要变更:新增 Baseline Profile 与 Startup Profile 生成模块、启动基准测试、profile 安装器,并启用 release 的 dex 布局优化。变更摘要中的 :baselineprofile 模块、BaselineProfileGenerator、StartupBenchmarks 及 build.gradle.kts 改动均与标题一致。标题简洁,符合 conventional commit 格式。

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.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 9bca9f8 and 892920f.

Files selected for processing: 1

  • baselineprofile/src/main/java/moe/ouom/neriplayer/baselineprofile/BaselineProfileGenerator.kt

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 4 remain after this review.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note

Quiet mode is enabled, so only the most important comments were posted inline. Other review comments are grouped below.

Other comments: 1

baselineprofile/src/main/java/moe/ouom/neriplayer/baselineprofile/BaselineProfileGenerator.kt: 1

29-29: Minor · Functional Correctness · Quick win

在首次引导启动前再次终止应用进程。

setOnboardingCompleted(false) 会通过 receiver 启动目标应用进程。此处直接调用 startActivityAndWait(),实际采集的是已有进程中的 Activity 启动,不是声明的首次引导冷启动路径。

请在广播完成后调用 killProcess(),与下面的常规冷启动路径保持一致。该操作会保留已写入的引导状态。

Review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 91b1379 and 9bca9f8.

Files ignored due to path filters: 4

  • CONTRIBUTING.md is excluded by !**/*.md
  • CONTRIBUTING_EN.md is excluded by !**/*.md
  • app/src/release/generated/baselineProfiles/baseline-prof.txt is excluded by !**/generated/**
  • app/src/release/generated/baselineProfiles/startup-prof.txt is excluded by !**/generated/**
Files selected for processing: 13

  • .gitignore
  • app/build.gradle.kts
  • app/src/benchmark/AndroidManifest.xml
  • app/src/benchmark/java/moe/ouom/neriplayer/benchmark/BaselineProfileFixtureReceiver.kt
  • baselineprofile/build.gradle.kts
  • baselineprofile/src/main/AndroidManifest.xml
  • baselineprofile/src/main/java/moe/ouom/neriplayer/baselineprofile/BaselineProfileGenerator.kt
  • baselineprofile/src/main/java/moe/ouom/neriplayer/baselineprofile/NeriPlayerJourney.kt
  • baselineprofile/src/main/java/moe/ouom/neriplayer/baselineprofile/StartupBenchmarks.kt
  • build-logic/convention/src/main/kotlin/build-logic.android.base.gradle.kts
  • build.gradle.kts
  • gradle/libs.versions.toml
  • settings.gradle.kts

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.

The fixture broadcast starts the app process, so kill it again before launching the onboarding screen to keep that journey a real cold start.
@cwuom
cwuom merged commit 6f77ad2 into master Nov 28, 2026
26 of 28 checks passed
@cwuom
cwuom deleted the perf/baseline-profile branch November 28, 2026 12:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant