grails-core icon indicating copy to clipboard operation
grails-core copied to clipboard

groovyCompile task takes 6 times longer in 4.1.0.M1 than 4.0.3

Open erichelgeson opened this issue 5 years ago • 8 comments

Task List

  • [x] Steps to reproduce provided
  • [ ] Stacktrace (if present) provided
  • [ ] Example that reproduces the problem uploaded to Github
  • [x] Full description of the issue provided (see below)

Steps to Reproduce

Update a large app (400+ controllers, 550+ services, 350 domains, 4000 files with 950k loc) to Grails 4.1.0.M1 + Gradle 5.6.4.

Using Gradle 5.6.4 with Java 8 & Grails 4.0.3 a clean/groovyCompile took approximately 5 minutes.

Expected Behaviour

Compile time should not be 6x longer.

Actual Behaviour

Using Gradle 5.6.4 with Java 11 & Grails 4.1.0.M1 a clean/groovyCompile takes 33 minutes on a 2019 MBP w/ 2.4 GHz 8-Core Intel Core i9 & 64gb of RAM.

It also seems no build-caching or compilation avoidance is applied, a re-run of groovyCompile takes the same amount of time. In 4.0.3 I occasionally will have a complete compile avoidance, but it does not seem deterministic.

Environment Information

  • Operating System: 10.15.5
  • Grails Version: 4.0.3/4.1.0.M1
  • JDK Version: 8/11
  • Container Version (If Applicable): n/a

Example Application

  • n/a

I suspect the cause is the move from Groovy 2.5 to 3.0.

I have given the groovyCompile task 16gb of ram, no change in compile time.

erichelgeson avatar Jun 10 '20 15:06 erichelgeson

Oh boy. This is not good

davydotcom avatar Jun 10 '20 16:06 davydotcom

I also tried to set -Dgroovy.antlr4=false but running into many compile errors that were not present before.

tasks.withType(GroovyCompile) {
	configure(groovyOptions) {
		forkOptions.jvmArgs = ['-Xms32g', '-Xmx32g', 
                      '-XX:+TieredCompilation', '-XX:TieredStopAtLevel=1',
                      '-noverify', '-Dgroovy.antlr4=false']
	}
}

erichelgeson avatar Jun 10 '20 18:06 erichelgeson

For reference https://issues.apache.org/jira/browse/GROOVY-9588

erichelgeson avatar Jun 29 '20 15:06 erichelgeson

Adding the new cache params does speed compile up significantly to 6 minutes slightly longer than 4.0.3, but in the range of usable)

Grails should add a bit higher defaults for the cache as most (Grails) projects would hit the default cache limits.

erichelgeson avatar Jul 02 '20 13:07 erichelgeson

@erichelgeson Since Grails 5 is still on groovy 3.x, I assume this continues to be an issue? Have you tried testing without these settings in Grails 5? We're experiencing increasingly longer build times lately and adjusting our GroovyCompile does not seem to have the benefits advertised in the GROOVY bug ticket:

  tasks.withType(GroovyCompile) {
    configure(options) {
        encoding = "utf-8"
        incremental = true
        fork = true
    }
    configure(groovyOptions) {
        encoding = "utf-8"
        fork = true
        optimizationOptions.indy = false
    }
    configure(groovyOptions.forkOptions) {
        memoryMaximumSize = "6g"
        jvmArgs = ['-Xmx6g', '-Dgroovy.parallel.parse=true', '-Dgroovy.antlr4.cache.threshold=0']
    }
}

jdaugherty avatar Apr 07 '23 18:04 jdaugherty

I can answer this. Groovy 3 uses a new parser and this parser is notably slower on LARGE groovy files. If your project has individual .groovy classes with large line counts it can cause this dramatic slowdown. It has been suggested that groovy4 increases this performance by quite a bit but still not quite on par with what groovy 2 was.

davydotcom avatar Apr 07 '23 19:04 davydotcom

Thanks @davydotcom - are you aware of a threshold that this becomes a problem?

jdaugherty avatar Apr 07 '23 20:04 jdaugherty

There was a groovy- JIRA related to it I cannot seem to track down off hand but I remember their example being beyond 4000 lines of code causing almost a 30 second build time for just one file. But it exponentially dropped when lower than that. I'll see if I can find the JIRA ticket

davydotcom avatar Apr 07 '23 20:04 davydotcom