|Faster Buck From Facebook|
|Written by Kay Ewbank|
|Monday, 13 November 2017|
Facebook has added a new feature to Buck, its open-sourced fast build system. The addition can be used to get faster compile times for Android projects.
Buck is a build system developed and used by Facebook. It is optimized for the creation of small, reusable modules consisting of code and resources, and supports a variety of languages and platforms. It was originally open sourced four years ago, and since then has been improved in small stages by both Facebook and community developers. However, those improvements were, according to Facebook's Jonathan Keijo:
"incremental in nature and based on long-standing assumptions about the way software development works."
When thinking about how to move Buck forward, the developers at Facebook looked at the wider picture and questioned their core assumptions, according to Keijo:
"which led us deep into the nuances of the Java language and the internals of the Java compiler. In the end, we completely reimagined the way Buck compiles Java code, unlocking performance gains unachievable through incremental improvements."
The improvement in speed was achieved by modifying the way that Buck ignores elements of code that haven't changed when carrying out incremental builds. Developers using Buck can set up build rules for the different parts of their application, with some rules being dependent on rules further up the chain. Buck caches the output of each rule, and when it detects a change in a rule's output it will identify and rebuild only the dependent rules.
Where a rule compiles Java code, Buck (until now) would do a basic comparison of the output JAR file, and if it was different to the cached one, would rebuild it along with any rules specified as being dependent. However, many changes to Java source code can result in a different JAR file but wouldn't actually affect the rules down the dependency line. One common example of this is where the dependents don't use all the classes in the rule, but Buck would rebuild all dependents when any class in the higher level JAR changed.
The new version of Buck was trained to detect which classes are used by a rule by monitoring which classes are read by the Java compiler. Now Buck encodes that information in dependency files to look for changes in only those classes when deciding what to rebuild. This feature is called "source-only stub generation", and it's one of the major things that makes the new version so much faster.
Another improvement is the avoidance of bottlenecks when building multiple rules. If a commonly-used rule takes a while to build, its dependents have to wait. However, as the Java compiler actually has all the information needed to build a stub JAR roughly halfway through its run, Buck can let dependent rules start compiling while the compiler is still finishing up their dependencies.
The new faster version is available on the BuckBuild website, as well as for instructions on making your code compatible, and an autofix script to do most of the work for you.
or email your comment to: email@example.com
|Last Updated ( Tuesday, 14 November 2017 )|