Android Baseline Profiles: Pre-compiling for Speed

A Baseline Profile is a cheat sheet for the Android runtime, telling it which code to pre-compile for faster performance. This speeds up app startup and reduces UI jank in critical flows.
Why it exists
Android's runtime (ART) compiles code as it's needed (Just-In-Time, or JIT), which can cause slowdowns and UI stutter, especially on first launch. Compiling everything Ahead-Of-Time (AOT) makes app installs huge and slow. Baseline Profiles solve this by identifying a small, critical set of code for AOT compilation, giving you the speed of AOT without the size penalty.
The mental model
Think of it as a mise en place for your app. Instead of a chef chopping vegetables for every order (JIT), you give them a prep list for your most popular dishes. Those ingredients are prepped ahead of time (AOT via Baseline Profile), making service instant. Less common orders are still prepped on the fly.
How it works
You define critical user journeys (CUJs) in automated tests, like launching the app and scrolling a list. When you run a special test to generate a profile, the system records every class and method touched during these journeys. This list is saved as a text file (baseline-prof.txt) in your app's source. When a user installs your app from the Play Store, the Android system uses this profile to AOT-compile the listed code, either at install time or during background device idle time.
When to use it
Use Baseline Profiles in any production Android app to improve startup performance and reduce jank. Google reports it can improve time to initial display by up to 40%. It is especially effective for apps with complex startup sequences or performance-sensitive UI, like scrollable lists. It's a standard part of modern Android performance optimization.
When not to use it
There are few reasons not to use them for a production app. The main overhead is setting up the generation process in your CI pipeline. For very simple apps or during early-stage debugging, the performance gain might not be worth the initial setup effort. The optimization is primarily handled by the system for store-based installs, so it's less impactful for apps distributed outside of Google Play.
One canonical example
A social media app defines a critical journey: the user launches the app, lands on their feed, and scrolls down ten items. The developer writes an instrumented test that automates this flow. Generating a Baseline Profile from this test creates a list of all methods involved in app initialization, view inflation, data fetching, JSON parsing, and RecyclerView rendering for those first ten items. This ensures the user's first interaction with the feed is as smooth as possible.
Interview question
How do Android Baseline Profiles primarily improve app startup and UI responsiveness?
- a.By forcing all application code to be compiled Ahead-Of-Time (AOT) during the installation process.
- b.By replacing the Just-In-Time (JIT) compiler with a more efficient, custom compilation engine.
- c.By compressing application assets and resources to reduce the overall app size.
- d.By providing the Android runtime with a list of critical code to pre-compile Ahead-Of-Time (AOT).Correct
Why? this is the answer
Baseline Profiles act as a 'cheat sheet' for the Android runtime, identifying a small, critical set of code paths for Ahead-Of-Time (AOT) compilation. This avoids the performance overhead of Just-In-Time (JIT) compilation for frequently used parts of the app, unlike option A which describes full AOT compilation that Baseline Profiles aim to selectively apply to avoid its drawbacks.
Just read this? Test yourself on what you have been reading.
Read the original → developer.android.com
- #android
- #performance
- #art
- #compilation
Put your scrolling time to good use
Learn one idea, try a quiz and save useful cards for revision. Tezvyn makes it easy to learn and stay current in your tech field, a few minutes at a time.
The iPhone app is on the way
We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.
Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.
We are hiring for this. Open roles that interview on android — each one lists the topics its interview covers.
See open roles