This is an automated email from the ASF dual-hosted git repository.
yiguolei pushed a commit to branch branch-4.0
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-4.0 by this push:
new b88a2057698 branch-4.0: [opt](memory) lazy-allocate PrefetchBuffer
backing buffer to reduce peak memory (#62004)
b88a2057698 is described below
commit b88a2057698932f131d413416617590789493ccb
Author: hui lai <[email protected]>
AuthorDate: Thu Apr 9 11:35:53 2026 +0800
branch-4.0: [opt](memory) lazy-allocate PrefetchBuffer backing buffer to
reduce peak memory (#62004)
pick https://github.com/apache/doris/pull/61482
---
be/src/io/fs/buffered_reader.cpp | 7 +++++++
be/src/io/fs/buffered_reader.h | 2 +-
2 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/be/src/io/fs/buffered_reader.cpp b/be/src/io/fs/buffered_reader.cpp
index 62774160555..b4f59146cd4 100644
--- a/be/src/io/fs/buffered_reader.cpp
+++ b/be/src/io/fs/buffered_reader.cpp
@@ -449,6 +449,13 @@ void PrefetchBuffer::prefetch_buffer() {
_prefetched.notify_all();
}
+ // Lazy-allocate the backing buffer on first actual prefetch, avoiding the
cost of
+ // pre-allocating memory for readers that are initialized but never read
(e.g. when
+ // many file readers are created concurrently for a TVF scan over many
small S3 files).
+ if (!_buf) {
+ _buf = std::make_unique<char[]>(_size);
+ }
+
int read_range_index = search_read_range(_offset);
size_t buf_size;
if (read_range_index == -1) {
diff --git a/be/src/io/fs/buffered_reader.h b/be/src/io/fs/buffered_reader.h
index 5fe07176235..709c0439b24 100644
--- a/be/src/io/fs/buffered_reader.h
+++ b/be/src/io/fs/buffered_reader.h
@@ -425,7 +425,7 @@ struct PrefetchBuffer :
std::enable_shared_from_this<PrefetchBuffer>, public Pro
_whole_buffer_size(whole_buffer_size),
_reader(reader),
_io_ctx(io_ctx),
- _buf(new char[buffer_size]),
+ _buf(nullptr),
_sync_profile(std::move(sync_profile)) {}
PrefetchBuffer(PrefetchBuffer&& other)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]