我的应用会扫描文件系统的一部分,我的用户在扫描网络驱动器时报告说它非常慢。测试我的代码,我发现了瓶颈:方法 File.isFile(), File.isDirectory(),以及 File.isHidden(),它们都在调用 fs.getBooleanAttributes(File f)。在Windows网络驱动器上,此方法似乎非常慢。如何提高性能?我可以避免以某种方式调用此方法吗?
My app scans part of a file system, and my users reported it was very slow when they were scanning a network drive. Testing my code, I identified the bottleneck: the methods File.isFile(), File.isDirectory(), and File.isHidden(), which are all calling fs.getBooleanAttributes(File f). This method appears to be very slow on Windows network drives. How can I improve performance? Can I avoid calling this method in some way?
推荐答案您是如何构建此文件列表的?除非您同时显示系统中的每个文件,否则您应该有一些选项...
How are you building this file list? Unless you are displaying every file on the system at the same time, you should have some options...
也许如果您展示用于构建列表的代码,我们可以找到其他一些改进的方面。 (为什么不能根据用于收集信息的方法推断出类型?如果你正在调用像GetFiles()这样的方法,你不知道返回的所有内容都是文件吗?)
Perhaps if you show the code you are using to build the list, we could find some other areas of improvement. (Why can't you just infer the type based on the method used to gather the information? If you're calling a method like GetFiles() don't you already know that everything returned is a file?)
更多推荐
加快文件系统访问速度?
发布评论