Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(encoding): use estimate size to reserve memory in row encoding #8909

Merged
merged 4 commits into from
Mar 31, 2023
Merged
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
12 changes: 10 additions & 2 deletions src/common/src/row/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,23 @@ pub trait Row: Sized + std::fmt::Debug + PartialEq + Eq {
/// Serializes the row with value encoding and returns the bytes.
#[inline]
fn value_serialize(&self) -> Vec<u8> {
let mut buf = Vec::with_capacity(self.len()); // each datum is at least 1 byte
let estimate_size = self
.iter()
.map(value_encoding::estimate_serialize_datum_size)
.sum();
let mut buf = Vec::with_capacity(estimate_size);
self.value_serialize_into(&mut buf);
buf
}

/// Serializes the row with value encoding and returns the bytes.
#[inline]
fn value_serialize_bytes(&self) -> Bytes {
let mut buf = BytesMut::with_capacity(self.len()); // each datum is at least 1 byte
let estimate_size = self
.iter()
.map(value_encoding::estimate_serialize_datum_size)
.sum();
let mut buf = BytesMut::with_capacity(estimate_size);
self.value_serialize_into(&mut buf);
buf.freeze()
}
Expand Down