This PR optimizes string concatenation in `URL::toExternalForm`. This method is called by `URL:toString` and executes often enough to be noticed during startup / classloading profiling. It was previously optimized in JDK 10 via JDK-8193034, but we can do more.
Key observations: * The current method concatenates concatenated strings. We can get away with less by flattening and concatenating once per call. * The current method does not take advantage of the fact that most URL components are optional and several are commonly not present. We can specialize for those cheaper common concatenations. This PR reduces runtime with 60% or more, depending on present URL components. (Benchmark results in first comment). I also ran the benchmark with compilation excluded and found no regressions for the interpreter case. Reviewers may find that the use of SSA-style local variables and the optimizations makes the code less dense and more verbose. I opted to not try to be clever and instead let the code "show its work" here. The code is more bulky, but hopefully should be easy to read. I added some code comments, happy to dial down those if requested. Feedback welcome! Performance refactoring, `noreg-perf`. `URL::toString` seems well tested by current tests. ------------- Commit messages: - Code comment cleanup - Fix code comment explaining output format - Optimize URL.toExternalForm by flattening concatenation and specializing for certain common patterns of optional components Changes: https://git.openjdk.org/jdk/pull/30151/files Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=30151&range=00 Issue: https://bugs.openjdk.org/browse/JDK-8379557 Stats: 147 lines in 2 files changed: 137 ins; 0 del; 10 mod Patch: https://git.openjdk.org/jdk/pull/30151.diff Fetch: git fetch https://git.openjdk.org/jdk.git pull/30151/head:pull/30151 PR: https://git.openjdk.org/jdk/pull/30151
