我们如何通过 baseline profiles 将 Android 启动时间削减 30%

Nobody likes waiting, especially when opening an app. We noticed a clear trend: the faster our app started, the more users stuck around. As part of our ongoing efforts to improve Android performance, we added baseline profiles, which reduced startup time by ~30%! 

没人喜欢等待,尤其是打开应用时。我们注意到一个明显趋势:应用启动越快,用户留存越多。作为持续改进 Android 性能的一部分,我们加入了 baseline profiles,将启动时间减少了约 30%!

But like all good engineering stories, the road to optimization wasn’t without challenges. We learned a lot while navigating testing setup issues and incompatible third-party libraries. Here's what happened behind the scenes, what we learned, and how it all paid off.

和所有优秀的工程故事一样,优化之路并非一帆风顺。我们在处理测试环境问题和第三方库不兼容的过程中学到了很多。以下是幕后发生的故事、我们的收获,以及最终如何收获回报。

What are baseline profiles?

什么是 baseline profiles?

Android apps store their code as bytecode in dex files, which your device must convert into machine code before the app can run. To understand why baseline profiles matter, let’s first explore how Android’s compilation methods have evolved.

Android 应用将代码以字节码形式存储在 dex 文件中,设备必须先把字节码转换成机器码,应用才能运行。要理解 baseline profiles 的重要性,我们先来看看 Android 的编译方式是如何演进的。

Imagine you're assigned a book for a foreign-language class, but you skipped your Duolingo lessons and haven't learned the language yet.

想象一下,你被指定在外语课上读一本书,但你跳过了 Duolingo 课程,还没学会这门语言。

Method:

方法:

Think of this as:

可以将其视为:

Technical Description:

技术说明:

Just-in-time (JIT) compilation

即时(JIT)编译

You look up every word as you read. If a phrase shows up a lot, you jot it down on a sticky note, but you toss it when you close the book.

你阅读时逢词必查。如果某个短语频繁出现,你就把它写在便利贴上,但合上书时就把便利贴扔掉。

Code is compiled as the app runs. Any optimizations made are discarded when the process dies.

代码在应用运行时编译,进程结束后所有优化都会被丢弃。

Full ahead-of-time (AOT) compilation

完全提前(AOT)编译

You decide translating as you go is too slow, so you memorize the entire language before even opening the book. Now reading the book is a breeze... but your book report is long overdue :(

你决定边读边翻译太慢,于是干脆在翻开书之前就把整门语言背下来。现在读书轻松多了……但你的读书报告早已逾期 :(

All code is compiled at install time. This results in gre...

开通本站会员,查看完整译文。

首页 - Wiki
Copyright © 2011-2025 iteam. Current version is 2.146.0. UTC+08:00, 2025-10-20 20:03
浙ICP备14020137号-1 $访客地图$