Support: Improve performance of FileOutputBuffer on Windows
authorRui Ueyama <ruiu@google.com>
Fri, 6 Mar 2015 06:07:32 +0000 (06:07 +0000)
committerRui Ueyama <ruiu@google.com>
Fri, 6 Mar 2015 06:07:32 +0000 (06:07 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@231452 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Support/FileOutputBuffer.cpp

index b176a8b45ab307a61da51b40b3e9843e0b81f42e..a35e160b2a1ba0c02efacabfd01abd53e7b8b7c0 100644 (file)
@@ -77,9 +77,16 @@ FileOutputBuffer::create(StringRef FilePath, size_t Size,
   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);