Great. I remember that FileInputStream's constructor also has performance problem. Maybe it was caused by the same reason.
On Mon, Mar 16, 2009 at 3:33 PM, Regis <[email protected]> wrote: > 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). >> >> 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 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. >> >> After patch HARMONY-6117, I got a great improvement when installed a > SecuirtyManager: > > hy: 49922ms > hy with patch: 15547ms > ri: 4250ms > > -- > Best Regards, > Regis. > -- Ray Chen MSN:[email protected] <msn%[email protected]> Email:[email protected] <email%[email protected]> QQ:4240464
