On Mon, 14 Jun 2021 13:43:40 GMT, Hannes Wallnöfer <hann...@openjdk.org> wrote:
> This change fixes a performance regression caused by passing instances of > `com.sun.tools.javac.util.Name` to a `html.markup.Text` object, where their > content is accessed using`CharSequence` methods which are implemented very > inefficiently. > > Since improving `javac.util.Name` will likely require a bit more work (see > JDK-8268622), a safe short term solution for JDK 17 is to make sure instances > of `Name` are converted to `String` before invoking said `CharSequence` > methods. The main fix is to convert to `String` early in > `Entity.escapeHtmlChars(CharSequence)` which is invoked by the `Text` > constructor. There are a few more `.toString()` invocations added in places > where a `Name` is appended to a `StringBuilder`, although these have less > performance impact. I've taken the time to run the benchmarks as well as I can, with no other apps running. I also ran it for the regression and the commit before the regression. As it turns out, the original performance loss is almost exactly the same as the improvement with the proposed fix. As to why my numbers are so different to the ones reported by Eric in JBS I don't know, but I guess there are a lot of variables (hardware, OS, command line options). commit 8cfea7c523fdda1375dc74bfc3a1042d45f2188e (before regression) Result "execute": 276,936 ±(99.9%) 2,292 ms/op [Average] (min, avg, max) = (269,618, 276,936, 286,777), stdev = 4,075 CI (99.9%): [274,644, 279,228] (assumes normal distribution) commit a5c4b9a6b078b12596e3e31f7f67e82f17181fdb (regression) Result "execute": 287,666 ±(99.9%) 2,187 ms/op [Average] (min, avg, max) = (279,349, 287,666, 293,730), stdev = 3,887 CI (99.9%): [285,480, 289,853] (assumes normal distribution) commit fe48ea9d7975188853bc165ce29789753f4758f2 (before proposed fix) Result "execute": 288,385 ±(99.9%) 1,498 ms/op [Average] (min, avg, max) = (284,871, 288,385, 296,769), stdev = 2,663 CI (99.9%): [286,887, 289,883] (assumes normal distribution) commit f6c876e472f82b8ff74e94e4e4d043bfaf145c4c (proposed fix) Result "execute": 276,643 ±(99.9%) 1,558 ms/op [Average] (min, avg, max) = (271,067, 276,643, 282,503), stdev = 2,770 CI (99.9%): [275,085, 278,201] (assumes normal distribution) ------------- PR: https://git.openjdk.java.net/jdk17/pull/42