[flang-commits] [flang] [llvm] [LLVM-Flang] Improve the realloc size for the write statement (PR #187662)
Eugene Epshteyn via flang-commits
flang-commits at lists.llvm.org
Fri Mar 20 05:57:33 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×
----------------
eugeneepshteyn wrote:
Note that `minBuffer` default value is 65536. It could be instantiated as `FileFrame<ExternalFileUnit, 256>`, for example. Please ensure your comments don't assume specific size and that this has reasonable behavior for the other buffer sizes.
https://github.com/llvm/llvm-project/pull/187662
More information about the flang-commits
mailing list