Excruciatingly Slow Initialization

This is a cross-post from a StackOverflow question that didn’t garner much interest. Hoping I can find some expertise in this forum that can help me out.

I am finding gradle incredibly slow. In particular, I have a large multi-module project, which takes a considerable amount of time to start-up and parse all the project definitions.

To illustrate this problem, I have created a simple scenario which illustrates how slow gradle is without the complexities of a multi-module project:

  • A completely empty build.gradle file
  • Run gradle without any parameters, and time how long it takes to parse the (empty) project file, and then exit showing me the usage statement: To run a build, run gradle <task> ...

This is taking roughly 2.5 seconds to execute, as noted by the Total Time .... output when gradle exits.

When modifying my gradle build scripts there is a lot of trial & error, making a change to build.gradle and then executing gradle build again. This means that I am constantly running into these delays when attempting to try-out my changes.

As noted on the StackOverflow question, adding apply plugin: java to the project adds yet more time to the otherwise empty build, adding another second to take the typical execution time to ~3.5 seconds.

On StackOverflow I also drew comparisons with Maven, which is orders of mangitude faster at parsing project configuration, and initializing projects.

Is there something I’m missing? I’ve not found any similar complaints, which suggests there’s somethign wrong with my set-up, or the wider community are happy with these delays?

One final note; my environment is Gradle 2.7 on Windows 7.

Do you have the daemon turned on? https://docs.gradle.org/current/userguide/gradle_daemon.html

No, the above timings are intentionally without enabling the daemon.

If I do enable the daemon the time it takes to start-up and print usage drops down to:

  • Empty build.gradle - 1.2 seconds
  • apply plugin: 'java' only - 1.4 seconds

This is still woefully slow, particularly when compared to the comparison of maven running at roughly ~0.1 second.

I am struggling to understand exactly what is taking so long to parse an empty file, and perform some very basic start-up?

I can’t reproduce those numbers.

In both cases, with Gradle and Maven a JVM needs to be fired up:

When I do: time mvn help without even being in a Maven project the result is:

real	0m1.046s
user	0m2.140s
sys	0m0.141s

When I do ‘time gradle help’ for a simple Java project, which does much more than a Maven help as it already evaluates and configured the build, I get the following results:

real	0m1.037s
user	0m1.122s
sys	0m0.111s

The startup cost of the client JVM that is communicating with the daemon is around 500ms. If you execute Gradle from an IDE you would not pay that cost.

What are you executing that gives you the numbers for Gradle?

Don’t rely on the numbers Maven tell you how long it took. They often deviate significantly from how long it actually took. Use the time command to get real data.