Android - Why does Android Boot relatively so slow?

Few years back, I worked on Android boot time optimization, as a Android developer. Obviously, as part of this work, we first needed to analyse where Android spends time during booting.

Below is the brief findings:

Hardware used : OMAP3430 Board which is like development board on which Stock Android is flashed. On actual commercial/production device, there will be additional specific hardware. To visualize the boot time, we used a developer tool called bootchart

The most time spend by Android is in following 2 areas:

  1. Zygote process. When android OS is started it will start Zygote process, it preloads classes to create a shared memory area for applications. This work of proloading of java classes takes @23 secs for its completion.

Why? Because The zygote class preloading is essential for good performance of the system after boot. So once classes are loaded of all apps, then run-time of app is much faster.

  1. Package manager service. In logcat output, we can see that Package manager scans 4 directories. /system/app, /system/framework, /data/app, /data/app-private.

Next, there is a component called Activity Manager which start differents services such as Location service, Telephony service etc. And it takes nearly 11-12 sec to finish this.

Why? Because, The package scan can in theory do some caching of its results after first boot and may check for security vulnerabilities.

If you add up these 2 times, it is about 35 Seconds

You may ignore these numbers in Today's day and age, but the point these number indicate is where Android AOSP code spends time during boot. OEMs have their own set of hardware which varies device to device.

Of course, there are other hardware and software initializations that Android needs to do after these 2 time consuming steps, which can stretch boot time further.

And is there anything as a user, I can do to speed up the booting process?

Not much I guess. The Android developer community and OEMs are still working on expediting the boot time but as you may imagine, it is not all that easy and making changes to optimize boot time may end up causing more app load time during normal operations, as hinted by Android framework engineer.


Android boot is slow?

My phone has a Quad Core, 3 Gig of RAM ... Android (Both KitKat and Lollipop) takes some 80 seconds to boot to completion.

My phone is only dual core with 1G RAM (Zenfone 4) and I never have that problem. Cold boot in ~60 seconds, reboot in 40-ish (CyannogenMod 12.1).

some users report less than 10 seconds booting time using Ubuntu with systemd and some 20 seconds ...

It depends on the config and what you considered "boot time". My laptop (i5 1st Gen, 4 GB RAM with spinning disk) is considered usable (finished booting) after about 90 seconds. Sure I can delay/disable some of the services to get faster boot time and start them manually as needed. But in my point of view, based on my preference, that won't count as usable.

On PC vs Mobile

There's some differences you should consider when comparing between pc and mobile linux. from CPU down to the kernel. Most notable differences:

  • Due to the nature of the device, mobile CPU mostly designed with power conservation as main consideration. This greatly affect performance.
  • Android kernel have some mobile-specific features which may affect boot time and hardware i/o access.
  • Furthermore, Android kernel known to have compatibility problems with mainline/stable. This is mostly due to vendor's preference to stick with old kernel version that compatible with their device drivers. AOSP Marshmallow runs 3.18.10 while stable kernel is currently at 4.6.2.

So, what makes Android boot so slow?

Why don't we check? :)

If you have access to adb and already enable Developer Options, check the boot log using

adb logcat -d -b events -v threadtime | grep "boot"

on my device, this is the output:

bambang@pamungkas ~ % adb logcat -d -b events -v threadtime | grep "boot"
06-08 04:35:01.417   193   193 I boot_progress_start: 9906
06-08 04:35:03.718   193   193 I boot_progress_preload_start: 12208
06-08 04:35:07.838   193   193 I boot_progress_preload_end: 16328
06-08 04:35:08.158   513   513 I boot_progress_system_run: 16647
06-08 04:35:09.880   513   513 I boot_progress_pms_start: 18370
06-08 04:35:10.204   513   513 I boot_progress_pms_system_scan_start: 18693
06-08 04:35:24.487   513   513 I boot_progress_pms_data_scan_start: 32977
06-08 04:35:28.552   513   513 I boot_progress_pms_scan_end: 37042
06-08 04:35:28.696   513   513 I boot_progress_pms_ready: 37186
06-08 04:35:33.088   513   513 I boot_progress_ams_ready: 41578
06-08 04:35:40.755   513   533 I boot_progress_enable_screen: 49244

As you can see, total boot time from VM start until initial screen drawing by window manager is ~40 seconds. Additional time on firmware & kernel space (on your linked asnwer, this translate to step 1-4) isn't included.

Notice that it takes ~18 secs to process the entire system's apk (boot_progress_pms_*), this translate to ~45% of boot time, which includes:

  • cleaning inexistent system packages and incomplete installation of packages,
  • validating installed apps,
  • setting library path,
  • etc (see: complete source code of PackageManagerService)

So generally, the total boot time is dependent with the number of packages (app) installed on the device. More app means longer wait during pms process. Additionally, starting activities takes ~5 sec / 20% of boot time. The rest is neither significant nor safely modifiable without deep knowlegde of system behaviors.

Is there anything I can do to speed up the booting process?

  • Try other ROM. Sony is one of the "good guys" who provide healthy environment for tweakers. I recommend AOSP or Cyanogen. Just be aware of the limitations
  • Test, don't assume! It's easy to make assumption that A boot slow, B is faster. A simple logcat command like above would reveal some useful infos for basic boot time benchmarking between ROMs.
  • If you know what you're doing, Embedded Linux Wiki have a list of possible tweaks to improve boot time.

On improving boot time

On your comment

ART was designed to make running apps faster. Who's working on one to make booting faster out of the box?

In my opinion, tweaking boot time is both unnecesarry and provide insignificant gain. Since your phone will, theoretically, stay up most of the time; it's far more important to maintain the system stability (with the tradeoff of longer boot process) to ensure higher uptime and less error.