summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support/FileOutputBuffer.cpp
diff options
context:
space:
mode:
authorRui Ueyama <ruiu@google.com>2015-03-06 06:07:32 +0000
committerRui Ueyama <ruiu@google.com>2015-03-06 06:07:32 +0000
commitda9bc2e56d5a5c6332a9def1a0065eb399182b93 (patch)
tree550f86fdbf7c2721e56555b73c9b219abf3477a5 /llvm/lib/Support/FileOutputBuffer.cpp
parent55905145e7cfe2adca541e7162b91d23a4e7f26c (diff)
downloadbcm5719-llvm-da9bc2e56d5a5c6332a9def1a0065eb399182b93.tar.gz
bcm5719-llvm-da9bc2e56d5a5c6332a9def1a0065eb399182b93.zip
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. llvm-svn: 231452
Diffstat (limited to 'llvm/lib/Support/FileOutputBuffer.cpp')
-rw-r--r--llvm/lib/Support/FileOutputBuffer.cpp7
1 files changed, 7 insertions, 0 deletions
diff --git a/llvm/lib/Support/FileOutputBuffer.cpp b/llvm/lib/Support/FileOutputBuffer.cpp
index b176a8b45ab..a35e160b2a1 100644
--- a/llvm/lib/Support/FileOutputBuffer.cpp
+++ b/llvm/lib/Support/FileOutputBuffer.cpp
@@ -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);
OpenPOWER on IntegriCloud