Skip to content

refactor(common): use BufMut impl in smallvec v2 for encoding #21056

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

Closed
wants to merge 1 commit into from
Closed
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
73 changes: 41 additions & 32 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ serde_default = "0.2"
serde_json = "1"
serde_with = "3"
smallbitset = "0.7.1"
smallvec = "1"
smallvec = { version = "2.0.0-alpha", features = ["bytes"] }
speedate = "0.15.0"
stacker = "0.1"
static_assertions = "1"
Expand Down
20 changes: 9 additions & 11 deletions src/common/src/util/value_encoding/column_aware_row_encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ struct Header {
/// `RowEncoding` holds row-specific information for Column-Aware Encoding
struct RowEncoding {
header: Header,
offsets: SmallVec<[u8; COLUMN_ON_STACK * 2]>,
offsets: SmallVec<u8, { COLUMN_ON_STACK * 2 }>,
data: Vec<u8>,
}

Expand Down Expand Up @@ -308,11 +308,10 @@ impl RowEncoding {
self.header.set_offset(offset_width);

self.offsets
.resize(usize_offsets.len() * offset_width.width(), 0);

let mut offsets_buf = &mut self.offsets[..];
.reserve(usize_offsets.len() * offset_width.width());
for &offset in usize_offsets {
offsets_buf.put_uint_le(offset as u64, offset_width.width());
self.offsets
.put_uint_le(offset as u64, offset_width.width());
}
}

Expand All @@ -327,7 +326,7 @@ impl RowEncoding {
);
let datums = datums.into_iter();
let mut offset_usize =
SmallVec::<[usize; COLUMN_ON_STACK]>::with_capacity(datums.size_hint().0);
SmallVec::<usize, COLUMN_ON_STACK>::with_capacity(datums.size_hint().0);
for (datum, data_type) in datums.zip_eq_debug(data_types) {
offset_usize.push(self.data.len());
datum.encode_to(data_type, &mut self.data);
Expand Down Expand Up @@ -378,16 +377,15 @@ pub struct Serializer<D: DataTypes = Vec<DataType>> {
data_types: D,
}

type EncodedColumnIds = SmallVec<[u8; COLUMN_ON_STACK * 4]>;
type EncodedColumnIds = SmallVec<u8, { COLUMN_ON_STACK * 4 }>;

fn encode_column_ids(column_ids: impl ExactSizeIterator<Item = ColumnId>) -> EncodedColumnIds {
// currently we hard-code ColumnId as i32
let mut encoded_column_ids = smallvec![0; column_ids.len() * 4];
let mut buf = &mut encoded_column_ids[..];
let mut buf = SmallVec::with_capacity(column_ids.len() * 4);
for id in column_ids {
buf.put_i32_le(id.get_id());
}
encoded_column_ids
buf
}

impl Serializer {
Expand Down Expand Up @@ -525,7 +523,7 @@ pub struct Deserializer<D: DataTypes = Arc<[DataType]>> {
#[derive(Clone)]
enum ColumnMapping {
/// For small number of columns, use linear search with `SmallVec`. This ensures no heap allocation.
Small(SmallVec<[i32; COLUMN_ON_STACK]>),
Small(SmallVec<i32, COLUMN_ON_STACK>),
/// For larger number of columns, build a `HashMap` for faster lookup.
Large(HashMap<i32, usize>),
}
Expand Down
Loading