Why bazel is faster than gradle

I originally use gradle

to build my android project, but lately I am porting it to bazel

and I found it is bazel

really faster than gradle

that, so I want to know why, but the doc bazel

doesn’t give much idea on this, can anyone me help?

Many thanks!

+3


source to share


1 answer


Full disclosure: I'm working on Bazel.

This is not an easy question to answer for two reasons. First, performance is highly scenario dependent. For example, we generally expect a clean build to be slower than a build where only one file has changed. Second, I don't know how Gradle works internally and they've done a lot of work recently to improve Gradle performance.

But I can talk about Basel and what we are doing to get it done quickly. We've been working on performance improvements for ~ 10 years, starting long before we release them.

The key feature is that we require all dependencies to be declared and we track them explicitly. If you are using a C ++ header file, or depend on a Java library, you must declare this dependency in your BUILD file (and we ensure they are sandboxed with separate actions). There are three effects:



First, we can parallelize the build a lot, because we know which things depend on other things.

Second, we can make incremental builds very fast because we can tell which parts of the build need to be redone when a specific file (BUILD file, header file, source file, ...) changes.

Third, we almost never need to do clean builds. Other build tools often require "make clean" to get into a predictable state - because Bazel knows all the dependencies, it can get a predictable state on every single build.

Another effect is that we can cache remotely (i.e. through users) and even execute on another machine, although neither is fully supported at the time of this writing.

+8


source







All Articles