Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions be/src/io/fs/buffered_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion be/src/io/fs/buffered_reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ struct PrefetchBuffer : std::enable_shared_from_this<PrefetchBuffer>, public Pro
_reader(reader),
_io_ctx_holder(std::move(io_ctx)),
_io_ctx(_io_ctx_holder.get()),
_buf(new char[buffer_size]),
_buf(nullptr),
_sync_profile(std::move(sync_profile)) {}

PrefetchBuffer(PrefetchBuffer&& other)
Expand Down
Loading