Skip to content

Commit

Permalink
speed up javac and error-prone tasks by using less resources (#11927) (
Browse files Browse the repository at this point in the history
…apache#1181)

Ports over apache/lucene#11927 and apache/lucene#11937 to Solr

Co-authored-by: Robert Muir <[email protected]>
Co-authored-by: Dawid Weiss <[email protected]>
  • Loading branch information
3 people authored Nov 17, 2022
1 parent bd11f3a commit 3b15605
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 6 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ plugins {
id 'ca.cutterslade.analyze' version "1.9.0"
id 'de.thetaphi.forbiddenapis' version '3.4' apply false
id "de.undercouch.download" version "5.2.0" apply false
id "net.ltgt.errorprone" version "2.0.2" apply false
id "net.ltgt.errorprone" version "3.0.1" apply false
id 'com.diffplug.spotless' version "6.5.2" apply false
id 'com.github.node-gradle.node' version '3.4.0' apply false
}
Expand Down
2 changes: 1 addition & 1 deletion gradle/generation/local-settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ systemProp.file.encoding=UTF-8
# The heap seems huge but gradle runs out of memory on lower values (don't know why).
#
# We also open up internal compiler modules for spotless/ google java format.
org.gradle.jvmargs=-Xmx3g \\
org.gradle.jvmargs=-Xmx3g -XX:TieredStopAtLevel=1 -XX:+UseParallelGC -XX:ActiveProcessorCount=1 \\
--add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED \\
--add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED \\
--add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED \\
Expand Down
32 changes: 30 additions & 2 deletions gradle/hacks/turbocharge-jvm-opts.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
allprojects {
def vmOpts = [
'-XX:+UseParallelGC',
'-XX:TieredStopAtLevel=1'
'-XX:TieredStopAtLevel=1',
'-XX:ActiveProcessorCount=1'
]

// Inject vm options into custom javadoc rendering. We can't refer
Expand All @@ -33,4 +34,31 @@ allprojects {
tasks.withType(JavaExec) {
jvmArgs += vmOpts
}
}

// Tweak javac to not be too resource-hungry.
// This applies to any JVM when javac runs forked (e.g. error-prone)
// Avoiding the fork entirely is best.
tasks.withType(JavaCompile) { JavaCompile task ->
task.options.forkOptions.jvmArgumentProviders.add(new CommandLineArgumentProvider() {
@Override
Iterable<String> asArguments() {
// Gradle bug: https://github.com/gradle/gradle/issues/22746
//
// Evaluation of this block is delayed until execution time when
// we know which "mode" java compiler task will pick and can set arguments
// accordingly.
//
// There is a side-effect to this that arguments passed via the provider
// are not part of up-to-date checks but these are internal JVM flags so we
// don't care.
//
// Pass VM options via -J only with a custom javaHome AND when java toolchains are not used.
if (task.options.forkOptions.javaHome != null && task.javaCompiler.getOrNull() == null) {
return vmOpts.collect {"-J" + it}
} else {
return vmOpts
}
}
})
}
}
2 changes: 1 addition & 1 deletion gradle/testing/defaults-tests.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ allprojects {
[propName: 'tests.haltonfailure', value: true, description: "Halt processing on test failure."],
// Default code cache size is 240m, but disabling C2 compiler shrinks it to 48m, which turns out to not be enough
[propName: 'tests.jvmargs',
value: { -> propertyOrEnvOrDefault("tests.jvmargs", "TEST_JVM_ARGS", "-XX:TieredStopAtLevel=1 -XX:ReservedCodeCacheSize=120m") },
value: { -> propertyOrEnvOrDefault("tests.jvmargs", "TEST_JVM_ARGS", "-XX:TieredStopAtLevel=1 -XX:+UseParallelGC -XX:ActiveProcessorCount=1 -XX:ReservedCodeCacheSize=120m") },
description: "Arguments passed to each forked JVM."],
// Other settings.
[propName: 'tests.neverUpToDate', value: true,
Expand Down
2 changes: 1 addition & 1 deletion help/localSettings.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ separately from the gradle workers, for example:
tests.jvms=3
tests.heapsize=512m
tests.minheapsize=512m
tests.jvmargs=-XX:+UseParallelGC -XX:TieredStopAtLevel=1
tests.jvmargs=-XX:+UseParallelGC -XX:TieredStopAtLevel=1 -XX:ActiveProcessorCount=1

Gradle Daemon
-------------
Expand Down

0 comments on commit 3b15605

Please sign in to comment.