Late last year, Facebook enhanced the performance of its Android application with a byte-code-optimizing tool called ReDex.
Now, ReDex has been open-sourced. Android developers can use the tool to optimize their own apps at no charge. They can also use it as the basis for other Android byte code optimizers.
In a post on Facebook's engineering blog, the company explained that classes in a .DEX file -- the executable format used in Android -- aren't organized by how they're accessed when the application starts, but simply by the order the build tooling encountered them.
ReDex uses trace data gathered from the running application to determine which classes should be placed first in the .DEX file, "[minimizing] the number of fetches from flash [storage] needed to load byte code on startup." Facebook claims optimizing its own app with ReDex reduced the on-disk footprint by 25 percent and sped up start time by 30 percent.
The speed, Facebook claimed, is most notable on older phones with slower flash memory, but newer phones showed a performance boost as well. Facebook's test bed was "a clean Nexus 4 running Android 4.4" (an OS version used by about 35 percent of Android handsets), with launch time for its app shaved down from 2 seconds to 1.6 seconds.
Runtime analysis is also used to strip out metadata and interfaces that aren't accessed, but the developer can supply hints to ReDex about how to conduct the optimization. For instance, it can instruct some methods to be left alone even if they're not directly accessed.
These optimizations happen after the app build process has finished. This means, in theory, they can complement other optimizations for Java that take place at the VM level or the language level, like the upcoming language-modularity features planned for Java 9.
Optimizing Java byte code isn't a new concept. At least one other open source project, ProGuard, optimizes Java applications by pruning unused code. But ProGuard apparently does not organize classes by order of execution, as ReDex does.
Sign up for CIO Asia eNewsletters.