Skip to content

Commit dbe5efe

Browse files
buchgrChris Parsons
authored and
Chris Parsons
committed
jdk: use parallel old gc and disable compact strings
When switching to JDK9 we regressed on java build performance by about ~30%. We found that when using parallel gc instead of G1 and disabling compact strings for JavaBuilder, the java build performance is "only" 10% slower. We additionally found JDK9 to have a significantly higher startup time. This impacts the performance of tools like javac and tubine and we believe that this accounts for most of the remaining overhead that can't be explained by disabling G1 and compact strings. java8 -version: 80ms java9 -version: 140ms java10 -version: 110ms Additionally, we found that the number of modules shipped with the JDK have a direct effect on the startup time. When building Java 10 with only the 9 modules required by Bazel we find that the startup time reduces to 80ms (from 110ms) which is on par with Java 8. We thus expect the regression to be fixed by a future migration to Java 10, which should be done in one of the next Bazel releases. == Some benchmark results == https://github.com/google/protobuf $ bazel build :protobuf_java Bazel 0.15.2: 4.2s Bazel 0.16.0-rc2: 5.2s This Change: 4.2s https://github.com/jin/android-projects/tree/master/java_only $ bazel build :module0 Bazel 0.15.2: 8.2s Bazel 0.16.0-rc2: 11.5s This Change: 9.1s RELNOTES: None PiperOrigin-RevId: 205647957
1 parent 26d987d commit dbe5efe

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/main/cpp/blaze.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,8 +420,12 @@ static vector<string> GetArgumentArray(
420420

421421
// TODO(b/109998449): only assume JDK >= 9 for embedded JDKs
422422
if (!globals->options->GetEmbeddedJavabase().empty()) {
423-
// quiet warnings from com.google.protobuf.UnsafeUtil,
423+
// In JDK9 we have seen a slow down when using the default G1 collector
424+
// and thus switch back to parallel gc.
425+
result.push_back("-XX:+UseParallelOldGC");
424426
// see: https://github.com/google/protobuf/issues/3781
427+
428+
// quiet warnings from com.google.protobuf.UnsafeUtil,
425429
result.push_back("--add-opens=java.base/java.nio=ALL-UNNAMED");
426430
}
427431

tools/jdk/default_java_toolchain.bzl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ JDK8_JVM_OPTS = [
1919
]
2020

2121
JDK9_JVM_OPTS = [
22+
# In JDK9 we have seen a ~30% slow down in JavaBuilder performance when using
23+
# G1 collector and having compact strings enabled.
24+
"-XX:+UseParallelOldGC",
25+
"-XX:-CompactStrings",
2226
# Allow JavaBuilder to access internal javac APIs.
2327
"--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED",
2428
"--add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED",

0 commit comments

Comments
 (0)