Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,3 @@ assets {

}

// https://github.com/apache/grails-core/issues/15321
tasks.withType(GroovyCompile).configureEach {
groovyOptions.optimizationOptions.indy = false
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import groovy.transform.CompileStatic
import org.apache.tools.ant.taskdefs.condition.Os
import org.gradle.api.Project
import org.gradle.api.artifacts.dsl.DependencyHandler
import org.gradle.api.provider.Property
import org.gradle.util.internal.ConfigureUtil

import grails.util.Environment
Expand All @@ -42,6 +43,7 @@ class GrailsExtension {
GrailsExtension(Project project) {
this.project = project
this.pluginDefiner = new PluginDefiner(project)
this.indy = project.objects.property(Boolean).convention(false)
}

/**
Expand Down Expand Up @@ -76,6 +78,14 @@ class GrailsExtension {
*/
boolean micronautAutoSetup = true

/**
* Whether to enable Groovy's invokedynamic (indy) bytecode instruction for dynamic Groovy method dispatch.
* Disabled by default to improve performance (see GitHub issue #15293).
* When enabled, Groovy uses JVM invokedynamic instead of traditional callsite caching.
* To enable invokedynamic in build.gradle: grails { indy = true }
*/
final Property<Boolean> indy

DependencyHandler getPlugins() {
if (pluginDefiner == null) {
pluginDefiner = new PluginDefiner(project)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,14 @@ class GrailsGradlePlugin extends GroovyPlugin {
private void configureGroovyCompiler(Project project) {
Provider<RegularFile> groovyCompilerConfigFile = project.layout.buildDirectory.file('grailsGroovyCompilerConfig.groovy')

GrailsExtension grailsExtension = project.extensions.findByType(GrailsExtension)

project.tasks.withType(GroovyCompile).configureEach { GroovyCompile c ->
c.outputs.file(groovyCompilerConfigFile)

// Configure indy option from GrailsExtension
c.groovyOptions.optimizationOptions.indy = grailsExtension?.indy?.getOrElse(false) ?: false

Closure<String> userScriptGenerator = getGroovyCompilerScript(c, project)
c.doFirst {
// This isn't ideal - we're performing configuration at execution time, but the alternative would be having
Expand Down Expand Up @@ -216,6 +221,14 @@ class GrailsGradlePlugin extends GroovyPlugin {
c.groovyOptions.configurationScript = combinedFile
}
}

// Log indy status once per project after evaluation
project.afterEvaluate {
if (!grailsExtension?.indy?.getOrElse(false)) {
project.logger.lifecycle('Grails: Groovy invokedynamic (indy) is disabled to improve performance (see issue #15293).')
project.logger.lifecycle(' To enable invokedynamic: grails { indy = true } in build.gradle')
}
}
}

protected Closure<String> getGroovyCompilerScript(GroovyCompile compile, Project project) {
Expand Down
4 changes: 0 additions & 4 deletions grails-profiles/base/skeleton/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,3 @@ tasks.withType(Test).configureEach {
useJUnitPlatform()
}

// https://github.com/apache/grails-core/issues/15321
tasks.withType(GroovyCompile).configureEach {
groovyOptions.optimizationOptions.indy = false
}
Loading