Skip to content

Commit b5aa566

Browse files
nga888tru
authored andcommitted
[Support] Improve Windows performance of buffered raw_ostream
The "preferred" buffer size for raw_ostream is set to BUFSIZ which on Windows is only 512. This results in more calls to write and this overhead can have a significant negative impact on performance, especially when Anti-Virus is also involved. Therefore increase the "preferred" buffer size to 16KB for Windows. One example of where this helps is the LLD --Map option which dumps out the symbol map for a link. In a link of UE4, this change has been seen to improve the performance of the symbol map writing by more than a factor of 6. Differential Revision: https://reviews.llvm.org/D147340 (cherry picked from commit a3aa916)
1 parent 74e76ab commit b5aa566

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

llvm/lib/Support/raw_ostream.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,15 @@ raw_ostream::~raw_ostream() {
8484
}
8585

8686
size_t raw_ostream::preferred_buffer_size() const {
87+
#ifdef _WIN32
88+
// On Windows BUFSIZ is only 512 which results in more calls to write. This
89+
// overhead can cause significant performance degradation. Therefore use a
90+
// better default.
91+
return (16 * 1024);
92+
#else
8793
// BUFSIZ is intended to be a reasonable default.
8894
return BUFSIZ;
95+
#endif
8996
}
9097

9198
void raw_ostream::SetBuffered() {

0 commit comments

Comments
 (0)