[flang] [llvm] [LLVM-Flang] Improve the realloc size for the write statement (PR #187662)
Thirumalai Shaktivel via llvm-commits
llvm-commits at lists.llvm.org
Sun Mar 22 23:38:26 PDT 2026
================
@@ -150,7 +150,19 @@ template <typename STORE, std::size_t minBuffer = 65536> class FileFrame {
if (bytes > size_) {
char *old{buffer_};
auto oldSize{size_};
- size_ = std::max<std::int64_t>(bytes, size_ + minBuffer);
+ std::int64_t minBuffer_{minBuffer}, newSize{size_ + minBuffer_};
+ // Grow the buffer geometrically. Using larger expansion steps reduces the
+ // number of reallocations and prevents excessive mmap/munmap activity.
+ if (newSize > minBuffer_ * 16) {
+ if (newSize < minBuffer_ * 1024) {
+ // Between 1 MB and 64 MB -> 2×
----------------
Thirumalai-Shaktivel wrote:
Setting the constant value works well. I also checked by changing the default value to 256, and the run was quick.
It seems the problem is with the buffer size. Copying the whole buffer into a new block for every realloc takes time. This fix works.
I checked different ways of causing any problem, and it works fine. Do you see any issues with checking the constant value?
https://github.com/llvm/llvm-project/pull/187662
More information about the llvm-commits
mailing list