Skip to content

Commit

Permalink
[Enhancement] Skip memcpy when reading header from pagecache.
Browse files Browse the repository at this point in the history
Signed-off-by: Gavin <yangguansuo@starrocks.com>
  • Loading branch information
GavinMar committed Nov 30, 2023
1 parent 677b803 commit 9b4fc3e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
12 changes: 12 additions & 0 deletions be/src/block_cache/io_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,18 @@ class IOBuffer {

const IOBuf& const_raw_buf() const { return _buf; }

size_t backing_block_num() { return _buf.backing_block_num(); }

const char* backing_block_data(size_t i) {
return _buf.backing_block(i).data();
}

size_t backing_block_size(size_t i) {
return _buf.backing_block(i).size();
}

void clear() { _buf.clear(); }

private:
butil::IOBuf _buf;
};
Expand Down
9 changes: 7 additions & 2 deletions be/src/formats/parquet/page_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ Status PageReader::next_header() {
// prefer peek data instead to read data.
bool peek_mode = false;
IOBuffer buffer;
buffer.clear();
RETURN_IF_ERROR(_get_header(allowed_page_size, &page_buf, &peek_mode, &buffer));

header_length = allowed_page_size;
Expand Down Expand Up @@ -162,8 +163,12 @@ Status PageReader::_get_header(size_t allowed_page_size, uint8_t** page_buf, boo
if (res.ok()) {
_local_page_buffer.header.resize(allowed_page_size);
_local_page_buffer.offset = 0;
*page_buf = _local_page_buffer.header.data();
buffer->copy_to(*page_buf, allowed_page_size, 0);
if (buffer->backing_block_num() == 1 || buffer->backing_block_size(0) >= allowed_page_size) {
*page_buf = (uint8_t*)buffer->backing_block_data(0);
} else {
*page_buf = _local_page_buffer.header.data();
buffer->copy_to(*page_buf, allowed_page_size, 0);
}
_opts.stats->pagecache_read_bytes += buffer->size();
_opts.stats->pagecache_read_count++;;
return res;
Expand Down

0 comments on commit 9b4fc3e

Please sign in to comment.