[flang] runtime perf: larger I/O buffer growth increments
authorPeter Klausler <pklausler@nvidia.com>
Thu, 20 Jan 2022 22:09:05 +0000 (14:09 -0800)
committerPeter Klausler <pklausler@nvidia.com>
Mon, 31 Jan 2022 22:53:15 +0000 (14:53 -0800)
When reallocating an I/O buffer to accommodate a large record,
ensure that the amount of growth is at least as large as the
minimum initial record size (64KiB).  The previous policy was
causing input buffer reallocation for each byte after the minimum
buffer size when scanning input data for record termination
newlines.

Differential Revision: https://reviews.llvm.org/D118649

flang/runtime/buffer.h

index eec2841..0bc3e0a 100644 (file)
@@ -135,7 +135,7 @@ private:
     if (bytes > size_) {
       char *old{buffer_};
       auto oldSize{size_};
-      size_ = std::max<std::int64_t>(bytes, minBuffer);
+      size_ = std::max<std::int64_t>(bytes, size_ + minBuffer);
       buffer_ =
           reinterpret_cast<char *>(AllocateMemoryOrCrash(terminator, size_));
       auto chunk{std::min<std::int64_t>(length_, oldSize - start_)};