RFR: 8368633: (fs) Path.toRealPath(NOFOLLOW_LINKS) very slow on macOS

Alan Bateman alanb at openjdk.org
Fri Oct 10 08:13:50 UTC 2025


On Thu, 9 Oct 2025 19:23:30 GMT, Brian Burkhalter <bpb at openjdk.org> wrote:

>>> My thinking was that if equalsIgnoreCase == false then the file keys cannot be equal so there is no point checking them.
>> 
>> The encode + decode may may not be a perfect round trip so I don't think this would hold. I think the only safe approach is to compareTo with the byte representation, if they are not equal then need to stat to get the fileKey.
>
> It's not a reason to go forward if the equalsIgnoreCase test is invalid, but dropping this check effectively negates the performance improvement. The path `element` is being compared to all the entries in a DirectoryStream and only one of them will have `compareTo == 0`, so all the rest encountered before the match will need their keys checked.

I don't have data to support this but I would expect that the element name will exactly match an entry in the directory most of the time. One thing to try is split it into two scans of the directory, the first uses compareTo on the byte representation, the second is the slow case when there is no match and you have to look at the fileKey.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/27709#discussion_r2418861483


More information about the nio-dev mailing list