You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@solr.apache.org by kr...@apache.org on 2022/11/17 19:14:16 UTC

[solr] branch main updated: speed up javac and error-prone tasks by using less resources (#11927) (#1181)

This is an automated email from the ASF dual-hosted git repository.

krisden pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/solr.git


The following commit(s) were added to refs/heads/main by this push:
     new 3b15605f553 speed up javac and error-prone tasks by using less resources (#11927) (#1181)
3b15605f553 is described below

commit 3b15605f5532b9f933f9a50296f7f4dba39fa08d
Author: Kevin Risden <ri...@users.noreply.github.com>
AuthorDate: Thu Nov 17 14:14:10 2022 -0500

    speed up javac and error-prone tasks by using less resources (#11927) (#1181)
    
    Ports over apache/lucene#11927 and apache/lucene#11937 to Solr
    
    Co-authored-by: Robert Muir <rm...@apache.org>
    Co-authored-by: Dawid Weiss <da...@carrotsearch.com>
---
 build.gradle                             |  2 +-
 gradle/generation/local-settings.gradle  |  2 +-
 gradle/hacks/turbocharge-jvm-opts.gradle | 32 ++++++++++++++++++++++++++++++--
 gradle/testing/defaults-tests.gradle     |  2 +-
 help/localSettings.txt                   |  2 +-
 5 files changed, 34 insertions(+), 6 deletions(-)

diff --git a/build.gradle b/build.gradle
index d55483a834f..cff2bdb19dd 100644
--- a/build.gradle
+++ b/build.gradle
@@ -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
 }
diff --git a/gradle/generation/local-settings.gradle b/gradle/generation/local-settings.gradle
index 408f25e15a2..1f9530a6e2c 100644
--- a/gradle/generation/local-settings.gradle
+++ b/gradle/generation/local-settings.gradle
@@ -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 \\
diff --git a/gradle/hacks/turbocharge-jvm-opts.gradle b/gradle/hacks/turbocharge-jvm-opts.gradle
index cdb226a89b3..2e857d3a21c 100644
--- a/gradle/hacks/turbocharge-jvm-opts.gradle
+++ b/gradle/hacks/turbocharge-jvm-opts.gradle
@@ -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
@@ -33,4 +34,31 @@ allprojects {
     tasks.withType(JavaExec) {
         jvmArgs += vmOpts
     }
-}
\ No newline at end of file
+
+    // 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
+                }
+            }
+        })
+    }
+}
diff --git a/gradle/testing/defaults-tests.gradle b/gradle/testing/defaults-tests.gradle
index 8dfaf4e0c64..7eec42b4f93 100644
--- a/gradle/testing/defaults-tests.gradle
+++ b/gradle/testing/defaults-tests.gradle
@@ -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,
diff --git a/help/localSettings.txt b/help/localSettings.txt
index 4af8411d1c3..b4510563a7c 100644
--- a/help/localSettings.txt
+++ b/help/localSettings.txt
@@ -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
 -------------