Android 日历团队如何使用基准配置文件改进应用启动和卡顿问题
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
基准配置文件将代码执行速度提升高达 30%,
解释器和即时 (JIT) 编译
步数
。借助基准配置文件,您可以选择
希望进行优化,并且可以帮助改进应用启动、减少卡顿等。
从而提升用户留存率和评分等业务指标。
详细了解基准
个人资料。
Android 日历团队实现了基准配置文件,并观察到大约 20% 的应用
缩短了启动时间,并将慢帧或冻结的帧减少了约 50%。以下是
他们是如何实现这些绩效提升的
决定使用基准配置文件来衡量其影响。
云配置文件与基准配置文件
Android 日历团队一直在使用 Cloud
配置文件,也就是
是另一种基于真实用户的配置文件引导优化 (PGO) 方法
用户与应用之间的互动以下是云配置文件和基准配置文件的方法
比较:
配置文件类型 |
设置 |
涵盖的用户体验历程 |
在用户群中实现最佳效果 |
实现的影响 |
支持的 Android 版本 |
云配置文件 |
默认处于启用状态 |
根据真实用户数据自动选择 |
大 |
几天内 |
Android 9(API 级别 28)及更高版本 |
基准配置文件 |
由您配置 |
由您选择 |
所有尺寸 |
即时 |
Android 7(API 级别 24)及更高版本 |
Android 日历团队决定将基准配置文件添加到
这是因为他们将转向更快的每周发布周期。
虽然云配置文件可显著提升性能,但需要 1-2 天的时间
以达到最佳效果,因为他们依赖
汇总真实用户数据。使用基准作为云配置文件的补充
配置文件可为用户提供更多时间来体验最佳性能改进
。
此外,Android 日历团队能够
选择要将哪些关键用户历程 (CUJ) 具体包含在
您可以使用基准配置文件执行此操作。
通常,除了云配置文件之外,我们建议使用基准配置文件。
以获得最佳性能结果。
涵盖的用户体验历程
Android 日历团队选择在基准配置文件中添加两个 CUJ:
- 在日程视图中打开应用:最初是默认视图,因此请务必
针对首次使用应用或不更改应用名称的用户进行优化
默认设置。
- 在月视图中打开应用:基于用户为许多用户选择的视图
数据。要跟踪用户如何使用您的应用,您可以使用一些工具,例如
Firebase。
一般来说,您应该添加可为企业带来利润的 CUJ(如果
和最常见的 CUJ。详细了解如何选择
要优化的 CUJ,请参阅需要优化的事项
include。
实现
Android 日历小组针对
Jetpack Macrobenchmark 库
以生成基准配置文件,以便轻松与内部工具和集成
可伸缩性
以下是用于按计划打开应用的 Macrobenchmark 测试配置
视图:
@Test
fun generateProfile() =
baselineProfileRule.collect(PACKAGE_NAME, includeInStartupProfile = true) {
startActivityAndWait()
// Verify pre-existing recurring events and tasks are shown.
device.waitAndFindObject(By.text("Recurring event"), 20_000)
device.waitAndFindObject(By.text("Recurring task"), 20_000)
// Open drawer and verify selected view.
device.findObject(By.desc("Show Calendar List and Settings drawer")).click()
device.waitAndFindObject(By.desc("Schedule view, Selected"), 1_000)
}
使用对照版本衡量影响
由于基准配置文件与随附的 APK 密切相关
并在应用运行之前被纳入代码,就无法运行标准的 A/B 测试
以了解其影响。不过,Android 日历小组
使用对照版本准确衡量影响,
实质上仅向一部分用户发布新的应用版本
与上一发布版本类似的用户时,可以向他们展示广告。
使用基准配置文件后,他们立即看到以下重要的
改进。这些统计信息是
的设备数量以及所有用户(从日程视图和月视图开始的用户)中
可能会获得最大的好处,但其他用户也会受益于
优化共享进程,例如从
数据库。
- 交互式应用启动延迟时间中位数(最常见的场景)从
775 毫秒到 644 毫秒 (17%)
- 冷启动延迟时间的中位数从 1,058 毫秒缩短至 901 毫秒 (15%)
- 温启动延迟时间中位数已从 453 毫秒缩短至 378 毫秒 (17%)
- 时间安排和月观看次数的中位数卡顿帧速率降低了 42-60%
请注意,如果您将云配置文件与 Baseline 结合使用,
随着时间的推移,
第 1 周,因为云配置文件的生成。不过,您仍应
使用基准配置文件后,性能得到显著提升
实施的优化建议
如需详细了解工具和功能,请参阅以下资源:
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-27。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["没有我需要的信息","missingTheInformationINeed","thumb-down"],["太复杂/步骤太多","tooComplicatedTooManySteps","thumb-down"],["内容需要更新","outOfDate","thumb-down"],["翻译问题","translationIssue","thumb-down"],["示例/代码问题","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-07-27。"],[],[],null,["# How the Android Calendar team improved app startup and jank with Baseline Profiles\n\nBaseline Profiles improve code execution speed by up to 30% by avoiding\ninterpreter and just-in-time (JIT) [compilation\nsteps](https://source.android.com/docs/core/runtime/jit-compiler#architectural-overview)\nfor common user journeys. Baseline Profiles let you choose the user journeys you\nwant to optimize and can help improve app startup, reduce jank, and more---which\nin turn result in improved business metrics, such as user retention and ratings.\n[Learn more about Baseline\nProfiles](/topic/performance/baselineprofiles/overview).\n\nThe Android Calendar team implemented Baseline Profiles and observed \\~20% app\nstartup time improvement and \\~50% reduction in slow or frozen frames. Here's\nwhat they did end-to-end to achieve these performance wins, from why they\ndecided to use Baseline Profiles to how they measured impact.\n\nCloud Profiles v. Baseline Profiles\n-----------------------------------\n\nThe Android Calendar team had already been using [Cloud\nProfiles](/topic/performance/baselineprofiles/overview#cloud-profiles), which\nare another Profile Guided Optimization (PGO) method based on real-world user\ninteractions with the app. Here's how Cloud Profiles and Baseline Profiles\ncompare:\n\n| Profile type | Set up | User journeys included | Works best when user base is | Impact realized | Supported Android versions |\n|-------------------|--------------------|----------------------------------------------------|------------------------------|----------------------|-------------------------------------|\n| Cloud Profiles | Enabled by default | Chosen automatically based on real-world user data | Large | Within a couple days | Android 9 (API level 28) and higher |\n| Baseline Profiles | Configured by you | Chosen by you | All sizes | Immediate | Android 7 (API level 24) and higher |\n\nOne key reason the Android Calendar team decided to add Baseline Profiles to\ntheir codebase was because they were moving to a faster, weekly release cycle.\nWhile Cloud Profiles provide significant performance gains, it takes 1-2 days\nafter app launch for them to reach their peak impact because they rely on\naggregating real-world user data. Supplementing Cloud Profiles with Baseline\nProfiles gives users more time to experience peak performance improvements\nbefore the next app version rolls out.\n\nAdditionally, it was important for the Android Calendar team to be able to\nchoose which critical user journeys (CUJs) specifically are included in the\nprofile, which you can do using Baseline Profiles.\n\nGenerally, we recommend using Baseline Profiles in addition to Cloud Profiles,\nenabled by default, for the best performance outcomes.\n\nUser journeys included\n----------------------\n\nThe Android Calendar team chose to include two CUJs in their Baseline Profiles:\n\n- Opening the app in schedule view: initially the default view, so important to optimize for users using the app for the first time or who don't change the default settings.\n- Opening the app in month view: the chosen view for many users, based on user data. To track how users are using your app, you can use tools such as [Firebase](https://firebase.google.com/docs/analytics).\n\nGenerally, you should add the CUJs that are profitable for the business (if\napplicable) and CUJs that are most common. To learn more about how to choose\nCUJs to optimize, see [What to\ninclude](/topic/performance/baselineprofiles/overview#what-to-include).\n\nImplementation\n--------------\n\nThe Android Calendar team uses an internal wrapper for the\n[Jetpack Macrobenchmark library](/topic/performance/baselineprofiles/measure-baselineprofile)\nto generate Baseline Profiles for ease of integration with internal tools and\ngeneral scalability.\n\nHere's the Macrobenchmark test configuration for opening the app in schedule\nview: \n\n @Test\n fun generateProfile() =\n baselineProfileRule.collect(PACKAGE_NAME, includeInStartupProfile = true) {\n startActivityAndWait()\n // Verify pre-existing recurring events and tasks are shown.\n device.waitAndFindObject(By.text(\"Recurring event\"), 20_000)\n device.waitAndFindObject(By.text(\"Recurring task\"), 20_000)\n\n // Open drawer and verify selected view.\n device.findObject(By.desc(\"Show Calendar List and Settings drawer\")).click()\n device.waitAndFindObject(By.desc(\"Schedule view, Selected\"), 1_000)\n }\n\nMeasure impact using controlled releases\n----------------------------------------\n\nSince Baseline Profiles are tightly coupled with the APK they're shipped with\nand incorporated before your app runs, it's not possible to run a standard A/B\nexperiment to understand their impact. However, the Android Calendar team was\nable to get an accurate measure of impact using *controlled releases*, where you\nessentially release the new app version to only a subset of users and compare\nthem to users who are on a version similar to the previous release.\n\nWith Baseline Profiles, they saw the following immediate, significant\nimprovements in multiple areas. These stats are aggregated across a wide range\nof devices and across all users---those who start in schedule and month view\nlikely gain the biggest benefits, but other users also benefit due to the\noptimization of shared processes such as loading calendar data from the\ndatabase.\n\n- Median interactive app startup (most common scenario) latency decreased from 775ms to 644ms (17%)\n- Median cold start latency decreased from 1,058ms to 901ms (15%)\n- Median warm start latency decreased from 453ms to 378ms (17%)\n- Median janky frame rate decreased by 42-60% in schedule and month views\n\nKeep in mind that if you use Cloud Profiles in conjunction with Baseline\nProfiles you'll likely see the improvements decrease slightly over the course of\nthe first week, as Cloud Profiles are generated. However, you should still\nobserve significant performance gains with Baseline Profiles on top of other\noptimizations you have in place.\n\nTo learn more about the tools and features, see the following resources:\n\n- [About Baseline Profiles](/topic/performance/baselineprofiles/overview)\n- [Benchmark Baseline Profiles with Macrobenchmark\n library](/topic/performance/baselineprofiles/measure-baselineprofile)"]]