[compiler-rt] r182563 - Performance improvement.

Bill Wendling isanbard at gmail.com
Thu May 23 13:01:38 PDT 2013


On May 23, 2013, at 11:24 AM, Benjamin Kramer <benny.kra at gmail.com> wrote:

> On 23.05.2013, at 09:18, Bill Wendling <isanbard at gmail.com> wrote:
> 
>> Author: void
>> Date: Thu May 23 02:18:59 2013
>> New Revision: 182563
>> 
>> URL: http://llvm.org/viewvc/llvm-project?rev=182563&view=rev
>> Log:
>> Performance improvement.
>> 
>> Using fwrite and fread was very *very* slow. The resulting code was multiple
>> times slower than GCC's implementation of gcov. Replace the fwrite/fread system
>> with an mmap() version.
>> 
>> If the `.gcda' file doesn't exist, we (re)allocate a buffer that we write
>> into. That gets written to the `.gcda' file in one chunk. If the `.gcda' file
>> already exists, we simply mmap() the file, modify the mapped data, and use
>> msync() to write the contents out to disk. It's much easier than implementing
>> our own buffering scheme, and we don't have to use fwrite's and fread's
>> buffering.
>> 
>> For those who are numbers-oriented, here are some timings:
>> 
>> GCC Verison
>> -----------
>> 
>> `.gcda' files don't exist:  23s
>> `.gcda' files do exist:     14s
>> 
>> LLVM Version (before this change)
>> ---------------------------------
>> 
>> `.gcda' files don't exist:  28s
>> `.gcda' files do exist:     28s
>> 
>> LLVM Version (with this change)
>> -------------------------------
>> 
>> `.gcda' files don't exist:  18s
>> `.gcda' files do exist:      4s
>> 
>> It's a win-win-win-win-lose-win-win scenario!
> 
> Since we're now dependent on mmap anyways, maybe the ftruncate trick helps in the "don't exist" case.
> 
> 1. open the file
> 2. ftruncate to the size we want (this extends the file with zeros)
> 3. mmap
> 
> Not sure if this actually increases performance in this case, but it may be worth a try.
> 
I’m not sure if that will help, because we don’t know the file’s size before we write to it. But the size doesn’t change (or shouldn’t change) after it’s created...

-bw





More information about the llvm-commits mailing list