Urgent.News

What's breaking now, across thousands of outlets.

Tech

Cold start in a 4.5 MB FOSS Android app: measure it with adb, then fix what's actually slow

Every "make your app faster" post opens with advice. This one opens with a number you can reproduce on your own device, because you can't fix a cold start you haven't measured. Here's the exact workflow I use on a 4.5 MB FOSS Android app, plus the two real things that were slowing its first frame. 1. Measure cold start with three commands (no Android Studio) A cold start means the process isn't…

This post demonstrates a practical method for improving the performance of a small, open-source Android app with a 4.5 MB APK size. The key points in the post are as follows:

1. To accurately measure an app's cold start time, avoid tapping the app icon in a running state, as this gives an artificially favorable result. Instead, forcefully stop the app using adb, start the app, and record the time taken from launch to the first frame, known as "ThisTime" in AOSP's ActivityMetricsLogger. Repeat this process multiple times and discard the first run, then calculate the median value.

2. The real culprit behind the app's slow cold start isn't necessarily its size but rather the numerous classes included in the release APK. In this case, the 4.5 MB APK contains an 8.4 MB classes.dex file, which is caused by not enabling R8's optimization and including unnecessary dependencies like Material Components and AppCompat.

3. The post then delves into the actual code that contributes to the slowness. The main culprits are SharedPreferences read and JSON rewrite calls in the onCreate() method, as well as synchronous IPC (inter-process communication) calls to system_server in onResume(). These calls, being on the critical path, significantly impact the cold-start process.

4. The author shares the recommended fixes in order of impact:

- Enable R8 (a tool for APK optimization) in the release build configuration to strip unused classes and reduce the APK size.

- Add a Baseline Profile to the app, which compiles hot paths into AOT-compiled code at installation time, resulting in faster app startup.

- Offload IPC calls from the onResume() method to improve performance.

- Avoid creating unnecessary Application subclasses, as their onCreate() methods run before the activity and add to the cold-start overhead.

5. To verify the effectiveness of the implemented changes, repeat the cold start measurement process before and after each change. Track the median of 10 cold runs instead of the minimum value, and revert any changes that don't improve the median time.

By following this step-by-step process, the open-source Android app in question can be optimized, leading to faster cold starts and an improved user experience.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

ghostwalk: an ofrenda for the forgotten files in your git repo

This is a submission for the Hacktoberfest Open-Source AI Challenge Week 4: Ghost in the Machine What I Built Every old repo has ghosts. Files nobody has opened in years.

  • Ghostwalk is a Python CLI tool for Git repositories
  • Identifies abandoned files, branches, and TODO/FIXME notes
  • Generates personalized epitaphs for "ghost" code elements

Moment: instant replay for Linux, with a clip library and a simple editor

I wanted a simple way to save something that had already happened during a game on Linux. That's what I've been working on with Moment: leave it running in the tray, press F8 after a good moment, and…

  • Moment captures game moments with F8 shortcut
  • Saved clips organized in local library with search and favorites
  • Clips exported as MP4 using four quality presets

More from Friday 30 October →