[patch, libfortran] [4.7/4.8/4.9 Regression] PR38199 missed optimization: I/O performance

Manfred Schwarb manfred99@gmx.ch
Sat Mar 8 22:55:00 GMT 2014


Am 08.03.2014 23:37, schrieb Manfred Schwarb:
> Am 08.03.2014 07:38, schrieb Jerry DeLisle:
>> The attached patch addresses the problem identified in comment #22 of the PR.
>> For character array internal unit reads, eat_spaces must call next_char to
>> advance every single character until the end of the string is reached.  In the
>> case sited which is very contrived, this amounts to about 100000 calls to next_char.
>>
>> For clarity, this test case:
>>
>>        character buffer(1)*100000
>>        integer i,j
>>
>>        j = 1234
>>        write(buffer(1),'(i4)') j
>>
>>        DO j=1,9999
>> !        write(*,*) buffer(1)(1:4)
>>          read(buffer,*) i
>> !        write(*,*) i
>>        ENDDO
>>        end
>>
>> Without the patch takes about 25 seconds to run.
>>
>> With the patch this takes about 2.8 seconds.
>
> This is great.
>
> However, this is still 10 times slower than the LEN_TRIM variant:
>          character buffer(1)*100000
>          integer i,j
>
>          j = 1234
>          write(buffer(1),'(i4)') j
>
>          DO j=1,9999
>   !        write(*,*) buffer(1)(1:4)
>            read(buffer(1)(1:LEN_TRIM(buffer(1))),*) i
>   !        write(*,*) i
>          ENDDO
>          end
>

and also 10 times slower than the scalar variant (which was fixed by Thomas):
       character buffer*100000
       integer i,j

       j = 1234
       write(buffer,'(i4)') j

       DO j=1,9999
!        write(*,*) buffer(1:4)
         read(buffer,*) i
!        write(*,*) i
       ENDDO
       end



> which takes 0.23s on my box. So on the on hand the improvement is great,
> on the other hand it is really sad, because the user will still
> need to do manual LEN_TRIM's when reading larger strings to get
> optimal performance...
>
> Thanks,
> Manfred
>
>
>
>>
>> The speedup is accomplished by simply skipping over spaces without calling
>> next_read, then backing up one character and letting the existing execution path
>> proceed, preserving all the end of record code needed in next_char.
>>
>> I also remove some unneeded error checks.
>>
>> Regression tested on X86_64 gnu.  No need for a new test case since no new
>> functionality is added.
>>
>> OK for trunk? The PR is marked as a regression, so I think this could be the
>> last piece and call it done.
>>
>> Regards,
>>
>> Jerry
>>
>> 2014-03-08  Jerry DeLisle  <jvdelisle@gcc.gnu>
>>
>>     PR libfortran/38199
>>     * io/list_read.c (next_char): Delete unuseful error checks.
>>     (eat_spaces): For character array reading, skip ahead over
>>     spaces rather than call next_char multiple times.
>>
>
>



More information about the Fortran mailing list