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

[Rust] [Experiment] Vec<u8> vs current allocations #8796

Closed
wants to merge 3 commits 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
10 changes: 4 additions & 6 deletions rust/arrow/src/array/array_binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ use std::{
};

use super::{
array::print_long_array, raw_pointer::as_aligned_pointer, raw_pointer::RawPtrBox,
Array, ArrayData, ArrayDataRef, FixedSizeListArray, GenericBinaryIter,
GenericListArray, LargeListArray, ListArray, OffsetSizeTrait,
array::print_long_array, raw_pointer::RawPtrBox, Array, ArrayData, ArrayDataRef,
FixedSizeListArray, GenericBinaryIter, GenericListArray, LargeListArray, ListArray,
OffsetSizeTrait,
};
use crate::util::bit_util;
use crate::{buffer::Buffer, datatypes::ToByteSlice};
Expand Down Expand Up @@ -209,9 +209,7 @@ impl<OffsetSize: BinaryOffsetSizeTrait> From<ArrayDataRef>
let value_data = data.buffers()[1].raw_data();
Self {
data,
value_offsets: RawPtrBox::new(as_aligned_pointer::<OffsetSize>(
raw_value_offsets,
)),
value_offsets: RawPtrBox::new(raw_value_offsets as *const OffsetSize),
value_data: RawPtrBox::new(value_data),
}
}
Expand Down
9 changes: 1 addition & 8 deletions rust/arrow/src/array/array_boolean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ use std::{convert::From, sync::Arc};
use super::*;
use super::{array::print_long_array, raw_pointer::RawPtrBox};
use crate::buffer::{Buffer, MutableBuffer};
use crate::memory;
use crate::util::bit_util;

/// Array of bools
Expand Down Expand Up @@ -148,10 +147,6 @@ impl From<ArrayDataRef> for BooleanArray {
"BooleanArray data should contain a single buffer only (values buffer)"
);
let raw_values = data.buffers()[0].raw_data();
assert!(
memory::is_aligned::<u8>(raw_values, mem::align_of::<bool>()),
"memory is not aligned"
);
Self {
data,
raw_values: RawPtrBox::new(raw_values as *const u8),
Expand Down Expand Up @@ -185,9 +180,7 @@ impl<Ptr: Borrow<Option<bool>>> FromIterator<Ptr> for BooleanArray {
let mut null_buf = MutableBuffer::new(num_bytes).with_bitset(num_bytes, false);
let mut val_buf = MutableBuffer::new(num_bytes).with_bitset(num_bytes, false);

let data = unsafe {
std::slice::from_raw_parts_mut(val_buf.raw_data_mut(), val_buf.capacity())
};
let data = val_buf.data_mut();

let null_slice = null_buf.data_mut();
iter.enumerate().for_each(|(i, item)| {
Expand Down
38 changes: 3 additions & 35 deletions rust/arrow/src/array/array_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ use std::mem;
use num::Num;

use super::{
array::print_long_array, make_array, raw_pointer::as_aligned_pointer,
raw_pointer::RawPtrBox, Array, ArrayDataRef, ArrayRef,
array::print_long_array, make_array, raw_pointer::RawPtrBox, Array, ArrayDataRef,
ArrayRef,
};
use crate::datatypes::ArrowNativeType;
use crate::datatypes::DataType;
Expand Down Expand Up @@ -118,7 +118,7 @@ impl<OffsetSize: OffsetSizeTrait> From<ArrayDataRef> for GenericListArray<Offset
);
let values = make_array(data.child_data()[0].clone());
let raw_value_offsets = data.buffers()[0].raw_data();
let value_offsets: *const OffsetSize = as_aligned_pointer(raw_value_offsets);
let value_offsets = raw_value_offsets as *const OffsetSize;
unsafe {
assert!(
(*value_offsets.offset(0)).is_zero(),
Expand Down Expand Up @@ -301,7 +301,6 @@ mod tests {
array::Int32Array,
buffer::Buffer,
datatypes::{Field, ToByteSlice},
memory,
util::bit_util,
};

Expand Down Expand Up @@ -781,35 +780,4 @@ mod tests {
.build();
ListArray::from(list_data);
}

#[test]
#[should_panic(expected = "memory is not aligned")]
fn test_primitive_array_alignment() {
let ptr = memory::allocate_aligned(8);
let buf = unsafe { Buffer::from_raw_parts(ptr, 8, 8) };
let buf2 = buf.slice(1);
let array_data = ArrayData::builder(DataType::Int32).add_buffer(buf2).build();
Int32Array::from(array_data);
}

#[test]
#[should_panic(expected = "memory is not aligned")]
fn test_list_array_alignment() {
let ptr = memory::allocate_aligned(8);
let buf = unsafe { Buffer::from_raw_parts(ptr, 8, 8) };
let buf2 = buf.slice(1);

let values: [i32; 8] = [0; 8];
let value_data = ArrayData::builder(DataType::Int32)
.add_buffer(Buffer::from(values.to_byte_slice()))
.build();

let list_data_type =
DataType::List(Box::new(Field::new("item", DataType::Int32, false)));
let list_data = ArrayData::builder(list_data_type)
.add_buffer(buf2)
.add_child_data(value_data)
.build();
ListArray::from(list_data);
}
}
19 changes: 0 additions & 19 deletions rust/arrow/src/array/array_primitive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ use super::array::print_long_array;
use super::raw_pointer::RawPtrBox;
use super::*;
use crate::buffer::{Buffer, MutableBuffer};
use crate::memory;
use crate::util::bit_util;

/// Number of seconds in a day
Expand Down Expand Up @@ -431,10 +430,6 @@ impl<T: ArrowPrimitiveType> From<ArrayDataRef> for PrimitiveArray<T> {
"PrimitiveArray data should contain a single buffer only (values buffer)"
);
let raw_values = data.buffers()[0].raw_data();
assert!(
memory::is_aligned::<u8>(raw_values, mem::align_of::<T::Native>()),
"memory is not aligned"
);
Self {
data,
raw_values: RawPtrBox::new(raw_values as *const T::Native),
Expand Down Expand Up @@ -466,13 +461,6 @@ mod tests {
assert!(arr.is_valid(i));
assert_eq!(i as i32, arr.value(i));
}

assert_eq!(64, arr.get_buffer_memory_size());
let internals_of_primitive_array = 8 + 72; // RawPtrBox & Arc<ArrayData> combined.
assert_eq!(
arr.get_buffer_memory_size() + internals_of_primitive_array,
arr.get_array_memory_size()
);
}

#[test]
Expand All @@ -492,13 +480,6 @@ mod tests {
assert!(!arr.is_valid(i));
}
}

assert_eq!(128, arr.get_buffer_memory_size());
let internals_of_primitive_array = 8 + 72 + 16; // RawPtrBox & Arc<ArrayData> and it's null_bitmap combined.
assert_eq!(
arr.get_buffer_memory_size() + internals_of_primitive_array,
arr.get_array_memory_size()
);
}

#[test]
Expand Down
9 changes: 3 additions & 6 deletions rust/arrow/src/array/array_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ use std::mem;
use std::{any::Any, iter::FromIterator};

use super::{
array::print_long_array, raw_pointer::as_aligned_pointer, raw_pointer::RawPtrBox,
Array, ArrayData, ArrayDataRef, GenericListArray, GenericStringIter, LargeListArray,
ListArray, OffsetSizeTrait,
array::print_long_array, raw_pointer::RawPtrBox, Array, ArrayData, ArrayDataRef,
GenericListArray, GenericStringIter, LargeListArray, ListArray, OffsetSizeTrait,
};
use crate::util::bit_util;
use crate::{buffer::Buffer, datatypes::ToByteSlice};
Expand Down Expand Up @@ -258,9 +257,7 @@ impl<OffsetSize: StringOffsetSizeTrait> From<ArrayDataRef>
let value_data = data.buffers()[1].raw_data();
Self {
data,
value_offsets: RawPtrBox::new(as_aligned_pointer::<OffsetSize>(
raw_value_offsets,
)),
value_offsets: RawPtrBox::new(raw_value_offsets as *const OffsetSize),
value_data: RawPtrBox::new(value_data),
}
}
Expand Down
10 changes: 0 additions & 10 deletions rust/arrow/src/array/array_union.rs
Original file line number Diff line number Diff line change
Expand Up @@ -414,16 +414,6 @@ mod tests {
let value = slot.value(0);
assert_eq!(expected_value, &value);
}

assert_eq!(
4 * 8 * 4 * mem::size_of::<i32>(),
union.get_buffer_memory_size()
);
let internals_of_union_array = (8 + 72) + (union.boxed_fields.len() * 144); // Arc<ArrayData> & Vec<ArrayRef> combined.
assert_eq!(
union.get_buffer_memory_size() + internals_of_union_array,
union.get_array_memory_size()
);
}

#[test]
Expand Down
Loading