RFR: 8259947: Optimize UnixPath.encode
Claes Redestad
redestad at openjdk.java.net
Tue Jan 19 00:51:09 UTC 2021
On Tue, 19 Jan 2021 00:35:51 GMT, Claes Redestad <redestad at openjdk.org> wrote:
> 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.
Microbenchmark results, baseline:
Benchmark Mode Cnt Score Error Units
FileToPath.mix avgt 15 1669.996 ± 76.308 ns/op
FileToPath.normalized avgt 15 349.300 ± 16.851 ns/op
FileToPath.notNormalized avgt 15 553.013 ± 28.736 ns/op
FileToPath.trailingSlash avgt 15 415.107 ± 18.322 ns/op
Target:
Benchmark Mode Cnt Score Error Units
FileToPath.mix avgt 15 887.191 ± 34.167 ns/op
FileToPath.normalized avgt 15 132.653 ± 2.907 ns/op
FileToPath.notNormalized avgt 15 333.678 ± 17.665 ns/op
FileToPath.trailingSlash avgt 15 192.272 ± 7.644 ns/op
-------------
PR: https://git.openjdk.java.net/jdk/pull/2135
More information about the core-libs-dev
mailing list