RFR: 8268622: Performance issues in javac `Name` class

Archie Cobbs acobbs at openjdk.org
Tue Aug 29 15:45:20 UTC 2023


Quoting [JDK-8268622](https://bugs.openjdk.org/browse/JDK-8268622):
> The javadoc team has identified performance issues in the javac `Name` class, particularly when it is used via its `CharSequence` interface ([JDK-8263321](https://bugs.openjdk.org/browse/JDK-8263321)). The main issue there is that the `CharSequence` is specifically character-oriented, whereas the native form inside javac is a byte[] in modified-UTF8 form. Operations like `.length()` and `.charAt(int)` have "simple" but very inefficient implementations.

Thanks to [JDK-8269957](https://bugs.openjdk.org/browse/JDK-8269957) we now have the option to swap in a `String`-based `Name` table implementation in place of the current UTF-8-based one. This does in fact improve performance of the compiler.

This patch does two things:
* Make the `String`-based `Name` table implementation the default. The two other UTF-8-based implementations are still available via the flags `-XDuseUnsharedTable=true` and `-XDuseSharedTable=true` (the latter was the previous default). This results in a 19% speedup in my simple benchmark (see below).
* Adds a new flag `-XDinternStringTable=true`, which turns on `intern()`ing of the `String`s in the `String` table. This however is **not** the default because it results in lower performance (see below). But it's possible this could help in other scenarios so it's left in there for future testing purposes.

Here are results from the [JavacNameTable.java](https://github.com/openjdk/jdk/files/12466359/JavacNameTable.java.txt) benchmark.

Benchmark                             Mode  Cnt   Score   Error  Units
JavacNameTable.testSharedTable        avgt   25  54.145 ± 1.738  ms/op
JavacNameTable.testStringTable        avgt   25  45.305 ± 0.415  ms/op
JavacNameTable.testStringTableIntern  avgt   25  50.736 ± 0.245  ms/op
JavacNameTable.testUnsharedTable      avgt   25  59.877 ± 2.503  ms/op

To reiterate: `testSharedTable` reflects the previous default; `testStringTable` reflects the new default. The other two options are available via the flags `-XDinternStringTable=true` and `-XDuseUnsharedTable=true`.

-------------

Commit messages:
 - Change the default Name table implementation to StringNameTable.

Changes: https://git.openjdk.org/jdk/pull/15470/files
 Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=15470&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8268622
  Stats: 18 lines in 2 files changed: 6 ins; 3 del; 9 mod
  Patch: https://git.openjdk.org/jdk/pull/15470.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/15470/head:pull/15470

PR: https://git.openjdk.org/jdk/pull/15470


More information about the compiler-dev mailing list