Facebook Revamps Open Source Tool for Faster Android Builds
Facebook has completely revamped a four-year-old open source tool it developed for code builds, resulting in faster compile times for Android projects.
Called Buck, the tool supports many languages and platforms, designed for developing small, reusable modules that combine source code and other resources.
Since Buck was launched as an open source project in April 2013 by Facebook, it has been improved by a number of incremental improvements from the company's devs and community contributors.
Facebook further studied the project, questioning some of the core assumptions about the way software development works in general and poking into the internals of Java and the Java compiler.
"In the end, we completely reimagined the way Buck compiles Java code, unlocking performance gains unachievable through incremental improvements," Facebook's Jonathan Keljo said in a blog post today titled "Rethinking Android App Compilation with Buck." "Today we're open-sourcing a new feature in Buck that will bring these performance improvements to Android engineers everywhere."
That feature is called "source-only stub generation"
While Keljo's extensive post dives deep into some of those Java internals to explain the underlying workings of the new feature, the bottom line is that a number of tweaks to Buck provide improvements for various functionalities ranging from 10 percent to 77 percent.
For example, he detailed the team's work with annotation processors for source-only stub generation. He described annotation processors as user-written plugins for the Java compiler that can generate new Java code in response to source code annotations.
"Instagram's build served as the test bed for this feature," Keljo said. "For that build, source-only stub generation reduced graph depth by 77 percent and cut cache fetches by 50 percent, which together reduced build times by 30 percent. We expect further improvements going forward as we remove some of the opt-outs, and we're working on rolling out the feature to our other Android apps."
Source-only stub generation is available now in Buck's GitHub repository, and Keljo pointed to documentation on how developers can leverage the new feature in their code, with the help of an autofix script.
Keljo also described other improvements to Buck. One involves streamlining the number of files that are rebuilt, basically by developing a way to detect what classes are used in build rules and putting that information in dependency files to ID changes in only those files, targeting them for rebuild.
This feature reduced the number of rules rebuilt by Buck by 35 percent, and its now available by default in the open source version of Buck.
Another feature, called rule pipelining, has reportedly reduced build times by 10 percent. It needs to be turned on by developers wishing to opt in for its use in the open source version of Buck.
David Ramel is the editor of Visual Studio Magazine.