> 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. > > Working on this PR revealed that current tests miss coverage for the case > where a query or ref component is the empty string. Some new test cases are > added to `Constructor.java`. Otherwise, `URL::toString` seems well tested by > current tests. > > Performance refactoring, `noreg-perf`.
Eirik Bjørsnøs has updated the pull request incrementally with seven additional commits since the last revision: - Add comment explaining why method is fast - Give up on vertical alignment - Shorten fast paths by using a ternary operator - Boolean locals for optionality allows tighter code - Fast paths can be moved to top of method - Add test cases for URLs with empty (blank, but non null) query and ref components - Fix regression caused by treating blank query or ref as not present ------------- Changes: - all: https://git.openjdk.org/jdk/pull/30151/files - new: https://git.openjdk.org/jdk/pull/30151/files/8f6f7b13..55f2266c Webrevs: - full: https://webrevs.openjdk.org/?repo=jdk&pr=30151&range=02 - incr: https://webrevs.openjdk.org/?repo=jdk&pr=30151&range=01-02 Stats: 44 lines in 2 files changed: 21 ins; 1 del; 22 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
