Groupon Michael Ma Dec 17, 2015

Android's Multidex Slows Down App Startup

Article Summary

Michael Ma from Groupon discovered that enabling multidex increased their Android app startup time by 15% on pre-Lollipop devices. Here's how his team clawed that performance back.

When Android apps hit the 65k method limit, multidex is the standard solution. But this convenience comes with a hidden cost: significantly slower app launches on devices running KitKat and below. Groupon's engineering team documented their journey to identify and fix this performance regression.

Key Takeaways

Critical Insight

By identifying and relocating startup-critical classes to the main dex file, Groupon eliminated the 15% performance penalty and matched pre-multidex startup speeds.

The article includes a utility class method and build.gradle script that automate finding which classes are slowing down your app startup.

About This Article

Problem

Groupon hit Android's 65k method limit and turned to multidexing. The Gradle plugin's Proguard analysis created an incomplete maindexlist.txt file, which led to java.lang.NoClassDefFoundError exceptions when the app started up.

Solution

Michael Ma's team made a multidex.keep file with the classes that were throwing NoClassDefFoundError exceptions. They wrote a build.gradle script that merged this file with the auto-generated maindexlist.txt before the app compiled.

Impact

The team used ClassLoader.findLoadedClass() at runtime to find which classes needed to load at startup, then moved those classes to the main dex file. This got Groupon's app startup performance back to where it was before multidexing, across all the devices they tested.