harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Regis <xu.re...@gmail.com>
Subject Re: [classlib] performance of java.io.File
Date Tue, 28 Apr 2009 07:32:41 GMT
Regis wrote:
> Hi all,
> 
> Recently I found our java.io.File implementation is obviously slower 
> than RI on Windows, especially when a SecurityManager is installed.
> 
> Testing with following simple test case:
> 
>         File file = new File("FilePerTest.java");
>         long start = System.currentTimeMillis();
>         for (int i = 0; i < 40000; ++i) {
>             file.isFile();
>             file.exists();
>             file.canRead();
>         }
>         long end = System.currentTimeMillis();
> 
> hy without SecuirtyManager    ri without SecuirtyManager
> 6766ms                1203ms
> 
> after installing a SecuirtyManager
> System.setSecurityManager(new SecurityManager());
> 
> hy with SecuirtyManager        ri with SecuirtyManager
> 54406ms                4078ms
> 
> We can see the gap is huge. After some investigations, I found two 
> problems in Harmony implemenation:
> 
> 1. Harmony used File.getCanonicalPath() in FilePermission, which is very 
> slow. Because if a SecurityManager was installed, every file operation 
> would be check by FilePermission, that cause the huge gap (54406ms 
> compare to 4078ms).

I found File.getCannoicalPath() invoke Windows API FindFirstFile on Widnows. 
Anyone know why we did this? I can't see any reasons, the path separator already 
fixed by File.fixSlashes, File.properPath got absolute path, 
File.getCanonicalPath remove "." and "..", no link to deal with on Windows, so 
seems everything has been done.

> 
> 2. in file native code file.c, ioh_convertToPlatform is called by every 
> method which "convert all separators to the proper platform separator 
> and remove duplicates on non POSIX platforms." (copied from comment of 
> method), that is exactly what File.fixSlashes did, I think they are 
> duplicated.

I have filed HARMONY-6186 to trace this.

> 
> I have created a JIRA HARMONY-6116 to track this issue, and sub-task 
> HARMONY-6117 for 1. A prototype patch already attach to HARMONY-6117, 
> your comments and suggestions are welcome.
> 


-- 
Best Regards,
Regis.

Mime
View raw message