By now, most chronic Facebook users with Android phones have upgraded to Facebook 2.0 for Android, which was released last Thursday. Completely redesigned and rewritten as a native app, Facebook 2.0 for Android improves the speed and performance of users’ interactions with their newsfeeds.
The reason for Android’s Facebook app update is that Facebook’s future will be determined by its success in tracking the mass migration of users from the PC to mobile devices. Success will be measured in increased mobile user engagement and the number of minutes spent in the Facebook mobile app. The increase in user engagement pushed the hybrid native/webview iOS and Android apps to the limit. Facebook decided to rewrite native apps for both iOS and Android to accomplish this. In doing so, Facebook gave up the Write-Once-Run-Everywhere (WORE) advantages of HTML5 that were the reason for writing hybrid native/webview versions. Facebook encountered the limits of HTML5 as a cross-platform framework, as have other cross-platform development efforts. Cross-platform frameworks fail when app designers are unable to match the scope of the app to the limits of the capabilities of the framework or when a rapidly evolving app grows beyond the limits of the framework.
Facebook’s engineering challenge was to orchestrate the processing of touch and the rendering of images and dynamic content to prevent a choppy user experience. Mobile devices don’t have the computing and graphics capability and the networks are not fast enough to deliver a smooth experience so app designers needed to engineer one by tightly managing the mobile device’s communications, memory, processing capability and storage. The iOS and Android Facebook native apps anticipate and cache to avoid the spinning wheel.
Webview on Android and UIWebView on iOS were major reasons to rewrite Facebook as purely native apps. Webview and UIWebview are programmatically accessible browsers the developer can implement to present HTML5 content. Both Webview and UIWebview are easier to implement than creating a native scrolling app, but the native scrolling app executes faster and does not have the burden of downloading big chunks of HTML content.
The improvements made to Facebook on iOS and Android are very similar, but the projects required different approaches and different development skills. So different that Facebook built separate teams for each mobile operating system. The common improvements made in both iOS and Android apps are:
- avoiding synchronous network access
- preloading content
- reusing newsfeed content so that it doesn’t need to be recreated as user scrolls.
The user’s first Facebook 2.0 for Android experience is guaranteed to be a poor one, but will quickly improve and demonstrate how Facebook improved the app’s responsiveness. When the app is first installed and the user starts to scroll up and down, the app becomes janky and jittery and the user quickly encounters a spinning wheel at the end of a short newsfeed. This is because not enough of the newsfeed has been downloaded to provide a cache of scrollable content and the data network is too slow to keep pace with the user’s scroll. If the user endures the janky and jittery experience, it gradually lessens until Facebook 2.0 for Android begins to operate as smoothly as Google’s native social network app Google Plus for Android. Looking at the storage usage of Facebook 2.0 for Android, one sees the evidence of how Facebook smoothed the scrolling experience in the increase in data storage and cache.
The Facebook development team wrote a custom "recycler" to create this improved scrolling experience, which simply recycles existing content so that precious computational and communications resources are not consumed to download again and recreate the newsfeed. This feature is the basis for scrolling up and down. Android provides a native recycling capability but Facebook decided to implement its own recycler optimized for Facebook’s unique and variable newsfeed content.
Facebook implemented the BitmapFactory class that improves memory efficiency by reducing the tedium of managing memory allocated to bitmap images and limiting the number of out-of-memory errors and memory leaks by letting Android automatically reclaim memory allocated to images when more storage is needed. A custom event bus was written to decouple the performance of the user interface from tasks that would degrade the scrolling experience, such as rendering an image.
In his Facebook blog post Under the Hood: Rebuilding Facebook for Android, Frank Qixing DU of the Facebook Android development team called this release a "solid foundation" putting in place the infrastructure to make "the app even faster, smoother, and feature-rich" in the future. And he’s right; there is a significant performance improvement that will make chronic Facebook use more chronic and casual use more engaging.