Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8368633

(fs) Path.toRealPath(NOFOLLOW_LINKS) very slow on macOS

XMLWordPrintable

    • b23
    • 20
    • generic
    • os_x

      ADDITIONAL SYSTEM INFORMATION :
      Mac OS X 15.6.1
      OpenJDK Runtime Environment 25+36-LTS

      A DESCRIPTION OF THE PROBLEM :
      Path.toRealPath(LinkOption.NOFOLLOW_LINKS) is 1000x slower than Path.toRealPath() on macOS. This was rather unexpected. I don't know if this is a JDK issue or a macOS platform issue.

      I have confirmed the issue with JDK 25 and JDK 24.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      On macOS, create 10.000 files and compare Path.toRealPath() to Path.toRealPath(LinkOption.NOFOLLOW_LINKS) runtime performance. The first test finishes almost instantly. The second test unexpectedly takes multiple minutes.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Adding LinkOption.NOFOLLOW_LINKS to Path.toRealPath() ideally shouldn't change the expected runtime performance completely.
      ACTUAL -
      TIME toRealPath(): 139 ms
      TIME toRealPath(LinkOption.NOFOLLOW_LINKS): 143.110 ms
      TIME toRealPath(): 113 ms


      ---------- BEGIN SOURCE ----------
      import java.io.File;
      import java.nio.file.LinkOption;
      import java.nio.file.Path;

      public class RealPathTest {

      public static void main(String[] args) throws Exception {
      System.out.println("* " + System.getProperty("os.name") + " " + System.getProperty("os.version"));
      System.out.println("* " + System.getProperty("java.runtime.name") + " " + System.getProperty("java.runtime.version"));

      Path[] files = new Path[10000];
      for (int i = 0; i < files.length; i++) {
      File f = File.createTempFile("RealPath" + i, ".tmp");
      f.deleteOnExit();
      files[i] = f.toPath();
      }

      long t1 = System.currentTimeMillis();
      for (Path f : files) {
      f.toRealPath();
      }
      System.out.format("TIME toRealPath(): %,d ms%n", System.currentTimeMillis() - t1);

      long t2 = System.currentTimeMillis();
      for (Path f : files) {
      f.toRealPath(LinkOption.NOFOLLOW_LINKS);
      }
      System.out.format("TIME toRealPath(LinkOption.NOFOLLOW_LINKS): %,d ms%n", System.currentTimeMillis() - t2);

      long t3 = System.currentTimeMillis();
      for (Path f : files) {
      f.toRealPath();
      }
      System.out.format("TIME toRealPath(): %,d ms%n", System.currentTimeMillis() - t3);
      }

      }

      ---------- END SOURCE ----------

            bpb Brian Burkhalter
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: