RFR: 8259947: Optimize UnixPath.encode

Claes Redestad redestad at openjdk.java.net
Tue Jan 19 00:51:09 UTC 2021


This patch improves `UnixPath.encode` by reusing `JLA.getBytesNoRepl` (which has fast-paths for common encoding) and avoiding a `toCharArray` call on the input by refactoring the `normalizeNativePath` code to operate on `String`. This might have a cost on files on Mac that need additional native normalization.

This removes another `ThreadLocal` and a source of `SoftReference`s. Together with the UTF-8 fast-path my UTF-8 encoded file system see substantial speed-ups in a trivial `new File(str).toPath()` microbenchmark.

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

Commit messages:
 - Add micro. To properly examine cost of toPath() needs a new File due caching - use FileOpen as a baseline
 - Optimize UnixPath.encode

Changes: https://git.openjdk.java.net/jdk/pull/2135/files
 Webrev: https://webrevs.openjdk.java.net/?repo=jdk&pr=2135&range=00
  Issue: https://bugs.openjdk.java.net/browse/JDK-8259947
  Stats: 138 lines in 6 files changed: 79 ins; 45 del; 14 mod
  Patch: https://git.openjdk.java.net/jdk/pull/2135.diff
  Fetch: git fetch https://git.openjdk.java.net/jdk pull/2135/head:pull/2135

PR: https://git.openjdk.java.net/jdk/pull/2135


More information about the core-libs-dev mailing list