RFR: 8321591: (fs) Path.of(URI) performance (win)

Brian Burkhalter bpb at openjdk.org
Thu Apr 3 01:16:46 UTC 2025


On Thu, 3 Apr 2025 01:07:34 GMT, Brian Burkhalter <bpb at openjdk.org> wrote:

> Improve the performance of `WindowsPathParser.normalize` by using a `char` array to perform the normalization in place instead of appending to a `StringBuilder`. The `Result` inner class is also converted to a `record`.

Performance changes as measured by the included benchmark are shown in the following table. The input path strings in even numbered rows include redundant backslashes (`\`).

| Path String | Baseline (ops/s) | Proposal (ops/s) | Change (%) |
| ----------- | ---------------- | ---------------- | ---------- |
| C:\Users\foo\bar\gus.txt | 6199154.628 | 6734399.308 | 8.34 |
| C:\Users\\\\foo\\\\bar\gus.txt | 5152600.992 | 6991821.398 | 35.69 |
| \\\.\UNC\localhost\C$\Users\foo | 4315495.741 | 4950377.343 | 14.71 |
| \\\.\UNC\localhost\C$\\\\Users\\\\foo | 4412610.277 | 5136928.053 | 15.41 |
| \\\?\C:\Users\foo\bar\gus.txt | 5401771.850 | 6332844.341 | 17.24 |
| \\\?\C:\Users\\\\foo\bar\\\\gus.txt | 5643219.553 | 6699547.423 |18.72 |
| .\foo\bar\gus.txt | 7354450.120 | 8967738.201 | 21.94 |
| .\foo\\\\bar\\\\gus.txt | 7179405.341 | 8816331.038 | 22.80 |
| \foo\bar\gus.txt | 8137737.571 | 9738842.924 | 19.68 |
| \foo\\\\bar\\\\gus.txt | 7966882.354 | 9444461.000 | 18.55 |
| C:foo\bar\gus.txt | 7917777.448 | 8489733.707 | 7.22 |
| C:foo\\\\bar\\\\gus.txt | 6986341.760 | 8583323.842 | 22.86 |

This proposed change affects `WindowsUriSupport.fromUri` as this method invokes `WindowsPathParser.parse` which in turn invokes `WindowsPathParser.normalize`. The opportunities for performance improvement in the code of `parse` proper appear to be limited due to the complexity of the Windows path design. Other URI-specific opportunities might exist in `fromUri` itself, for example, parsing only if the path component of the URI does not meet certain conditions, e.g., if it contains a slash `/`, redundant backslahes (`\`), or an invalid character (`:`, `|`, etc.)

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

PR Comment: https://git.openjdk.org/jdk/pull/24400#issuecomment-2774087281


More information about the nio-dev mailing list