You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@harmony.apache.org by Regis <xu...@gmail.com> on 2009/03/11 09:49:42 UTC

[classlib] performance of java.io.File

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.

-- 
Best Regards,
Regis.

Re: [classlib] performance of java.io.File

Posted by Regis <xu...@gmail.com>.
陈磊 wrote:
> Great.   I remember that FileInputStream's constructor also has  performance
> problem. Maybe it was caused by the same reason.

I guess so. Default, there is no SecurityManager installed, the gap with 
RI is not so huge, but still slow five times, need to be optimized.

> 
> On Mon, Mar 16, 2009 at 3:33 PM, Regis <xu...@gmail.com> 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.
>>
> 
> 
> 


-- 
Best Regards,
Regis.

Re: [classlib] performance of java.io.File

Posted by 陈磊 <cl...@gmail.com>.
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 <xu...@gmail.com> 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:clraychen@hotmail.com <MS...@hotmail.com>
Email:clarychen@gmail.com <Em...@gmail.com>
QQ:4240464

Re: [classlib] performance of java.io.File

Posted by Regis <xu...@gmail.com>.
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.

Re: [classlib] performance of java.io.File

Posted by Regis <xu...@gmail.com>.
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.