IBM / JTOpen

IBM Toolbox for Java, an IBM i communications library
https://ibm.github.io/JTOpen/
Other
56 stars 26 forks source link

Faster file attribute access #172

Open Stefan4112 opened 3 months ago

Stefan4112 commented 3 months ago

Reading the file attributes is very slow compared to Windows and Linux. In my example I add the size of all files in a specific directory. The directory contains 30.000 files with 32KB. On Windows it runs 135 ms and on AS400 1050 ms. That is 10x faster!

Other methods like File.listFiles() on AS400 are faster than Windows, but they still take 1000+ ms. Also tested IFSFile.listFiles() and SQL IFS access. So it would be nice if only accessing the file attributes would be faster.

# example: calculate file size in directory
private long walkWithJava7(String dirPath) throws IOException
{
    AtomicLong size = new AtomicLong(0);
    Path folder = Paths.get(dirPath);

    Files.walkFileTree(folder, new SimpleFileVisitor<Path>() {
          @Override
          public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException
              {
                  //Use attributes - creating File object is slow!
                  if(attrs.isRegularFile()) {
                      size.addAndGet(attrs.size());
                  }
                      return FileVisitResult.CONTINUE;
              }
      });

      return size.longValue();
}