Skip to content

Commit

Permalink
jdk: use parallel old gc and disable compact strings
Browse files Browse the repository at this point in the history
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
  • Loading branch information
buchgr authored and Copybara-Service committed Jul 23, 2018
1 parent ebdf218 commit 3842bd3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/main/cpp/blaze.cc
Original file line number Diff line number Diff line change
Expand Up @@ -420,8 +420,12 @@ static vector<string> GetArgumentArray(

// TODO(b/109998449): only assume JDK >= 9 for embedded JDKs
if (!globals->options->GetEmbeddedJavabase().empty()) {
// quiet warnings from com.google.protobuf.UnsafeUtil,
// In JDK9 we have seen a slow down when using the default G1 collector
// and thus switch back to parallel gc.
result.push_back("-XX:+UseParallelOldGC");
// see: https://github.com/google/protobuf/issues/3781

// quiet warnings from com.google.protobuf.UnsafeUtil,
result.push_back("--add-opens=java.base/java.nio=ALL-UNNAMED");
}

Expand Down
4 changes: 4 additions & 0 deletions tools/jdk/default_java_toolchain.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ JDK8_JVM_OPTS = [
]

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

0 comments on commit 3842bd3

Please sign in to comment.