RFR: 8314569: (fs) Improve normalization of UnixPath for directories [v3]

Sergey Tsypanov stsypanov at openjdk.org
Sat Aug 26 16:05:43 UTC 2023


> Avoiding `String.substring()` call in `UnixPath.normalize()` can significantly reduce normalization costs for directories on Linux:
> 
> @BenchmarkMode(Mode.AverageTime)
> @OutputTimeUnit(TimeUnit.NANOSECONDS)
> @Warmup(time = 2, iterations = 5)
> @Measurement(time = 2, iterations = 5)
> @Fork(value = 4, jvmArgs = "-Xmx1g")
> public class FileToPathBenchmark {
> 
>     @Benchmark
>     public Path toDirectoryPath(Data data) {
>         return FileSystems.getDefault().getPath(data.directoryPath);
>     }
> 
>     @State(Scope.Thread)
>     public static class Data {
>         private String directoryPath = "/tmp/tmp/tmp/";
>     }
> }
> 
> Results:
> 
> baseline
> 
> Benchmark                                                             Mode  Cnt     Score     Error   Units
> FileToPathBenchmark.toDirectoryPath                                   avgt   50    40.524 ±   0.940   ns/op
> FileToPathBenchmark.toDirectoryPath:·gc.alloc.rate                    avgt   50  3269.167 ± 101.018  MB/sec
> FileToPathBenchmark.toDirectoryPath:·gc.alloc.rate.norm               avgt   50   175.213 ±   1.200    B/op
> FileToPathBenchmark.toDirectoryPath:·gc.churn.G1_Eden_Space           avgt   50  3279.401 ± 104.252  MB/sec
> FileToPathBenchmark.toDirectoryPath:·gc.churn.G1_Eden_Space.norm      avgt   50   175.756 ±   1.681    B/op
> FileToPathBenchmark.toDirectoryPath:·gc.churn.G1_Survivor_Space       avgt   50     0.006 ±   0.001  MB/sec
> FileToPathBenchmark.toDirectoryPath:·gc.churn.G1_Survivor_Space.norm  avgt   50    ≈ 10⁻³              B/op
> FileToPathBenchmark.toDirectoryPath:·gc.count                         avgt   50  1412.000            counts
> FileToPathBenchmark.toDirectoryPath:·gc.time                          avgt   50  4144.000                ms
> 
> patched
> 
> Benchmark                                                             Mode  Cnt     Score     Error   Units
> FileToPathBenchmark.toDirectoryPath                                   avgt   50    33.134 ±   2.313   ns/op
> FileToPathBenchmark.toDirectoryPath:·gc.alloc.rate                    avgt   50  2652.997 ± 152.758  MB/sec
> FileToPathBenchmark.toDirectoryPath:·gc.alloc.rate.norm               avgt   50   115.210 ±   1.960    B/op
> FileToPathBenchmark.toDirectoryPath:·gc.churn.G1_Eden_Space           avgt   50  2654.258 ± 157.862  MB/sec
> FileToPathBenchmark.toDirectoryPath:·gc.churn.G1_Eden_Space.norm      avgt   50   115.200 ±   1.960    B/op
> FileToPathBenchmark.toDirectoryPath:·gc.churn.G1_Survivor_Space       avgt   50     0.007 ±   0.001  MB/sec
> FileToPathBenchmark.toDirec...

Sergey Tsypanov has updated the pull request incrementally with one additional commit since the last revision:

  Style clean-up

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

Changes:
  - all: https://git.openjdk.org/jdk/pull/15342/files
  - new: https://git.openjdk.org/jdk/pull/15342/files/1877ee9d..c4120be6

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk&pr=15342&range=02
 - incr: https://webrevs.openjdk.org/?repo=jdk&pr=15342&range=01-02

  Stats: 3 lines in 1 file changed: 0 ins; 2 del; 1 mod
  Patch: https://git.openjdk.org/jdk/pull/15342.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/15342/head:pull/15342

PR: https://git.openjdk.org/jdk/pull/15342


More information about the nio-dev mailing list