[llvm] r231452 - Support: Improve performance of FileOutputBuffer on Windows

Rui Ueyama ruiu at google.com
Thu Mar 5 22:07:32 PST 2015


Author: ruiu
Date: Fri Mar  6 00:07:32 2015
New Revision: 231452

URL: http://llvm.org/viewvc/llvm-project?rev=231452&view=rev
Log:
Support: Improve performance of FileOutputBuffer on Windows

We extend an underlying file before mmap'ing it, but it's not needed
on Windows. Extending file is slow on Windows, so we should avoid doing that.
The difference gets larger as the size of an output file gets larger.
It shove off 2 seconds out of 25 seconds when linking chrome.dll with LLD,
for example.


Modified:
    llvm/trunk/lib/Support/FileOutputBuffer.cpp

Modified: llvm/trunk/lib/Support/FileOutputBuffer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/FileOutputBuffer.cpp?rev=231452&r1=231451&r2=231452&view=diff
==============================================================================
--- llvm/trunk/lib/Support/FileOutputBuffer.cpp (original)
+++ llvm/trunk/lib/Support/FileOutputBuffer.cpp Fri Mar  6 00:07:32 2015
@@ -77,9 +77,16 @@ FileOutputBuffer::create(StringRef FileP
   if (EC)
     return EC;
 
+#ifndef LLVM_ON_WIN32
+  // On Windows, CreateFileMapping (the mmap function on Windows)
+  // automatically extends the underlying file. We don't need to
+  // extend the file beforehand. _chsize (ftruncate on Windows) is
+  // pretty slow just like it writes specified amount of bytes,
+  // so we should avoid calling that.
   EC = sys::fs::resize_file(FD, Size);
   if (EC)
     return EC;
+#endif
 
   auto MappedFile = llvm::make_unique<mapped_file_region>(
       FD, mapped_file_region::readwrite, Size, 0, EC);





More information about the llvm-commits mailing list