Facebook Embraces Open Source Approach for Redex App Development
ReDex, a tool for reducing Android app size and improve performance was launched by Facebook. There was work on optimizations to make the bytecode smaller, but it was not tested in production. With the first ReDex-optimized version of Facebook specifically for Android, the speed of loading is 30 percent faster. Also, the social media giant is open-sourcing ReDex, so that developers can leverage tools to make all types of Android apps better.
ReDex is actually an Android bytecode optimizing tool which is also a framework for reading, writing and analyzing all types of .dex files that enhance the bytecode. In a recent conference, Re-dex was announced to be open-sourced which is surely benefiting all developers.
With less bytes, one can expect faster installation time, faster runtimes and performance, along with faster download times and reduced data usage.
Here are the changes that enhance Redex from its previous version:
Feedback-directed class layout
The speedup was achieved by optimizing the app's bytecode layout on disk. When the app starts, the disk has to seek out random class data which is scattered in a very large file, thus leading to some delays within the internal flash storage. Optimizing class locality has helped in enhancing bytecode-loading performance.
Feedback-directed optimization (FDO) was performed after runtime data was gathered in the lab. All the classes are traced for a cold start on a set of test devices. The class trace is then fed into ReDex, which minimizes the number of fetches required for loading bytecode.
Removal of interfaces
Coding against interfaces is meant to be a good software engineering practice. However, sometimes an app release includes interfaces with a single implementation which takes up additional space in the memory space forcing for an additional dex. Calling interface might prove to be less efficient at runtime that resorting to calling of virtual methods.
ReDex removes unnecessary interfaces wherein one can see analysis pass that scours the class hierarchy and searches for interfaces with single implementor. Then one can traverse the code and rewrite method calls so that the implementation method is invoked and then eliminate the interface.
Removal of metadata
Dex files include metadata which is not required at runtime. A simple pass was made to strip outsource file references to be replaced with other strings. This optimization saved a huge amount of storage. Additionally, some annotations are required at runtime, while some are used in analysis tools or during the build process. A whitelist-based pass was used to eliminate unnecessary annotations.
Re-Dex optimizes before the assembly of .dex files into APK
ReDex focuses on getting the Android bytecode optimised and quick. With this aspect, one can have the maximum ability to perform global interclass optimizations across the binary level, rather than on the local class level.
