Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Faster file attribute access #172

Open
Stefan4112 opened this issue Apr 8, 2024 · 0 comments
Open

Faster file attribute access #172

Stefan4112 opened this issue Apr 8, 2024 · 0 comments

Comments

@Stefan4112
Copy link

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();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant