Skip to content

Commit 794fc4c

Browse files
committed
perf: align buffer to Alignment::DEFAULT_ALIGNMENT = = Alignment::new(256)
Signed-off-by: Joe Isaacs <joe.isaacs@live.co.uk>
1 parent 202953d commit 794fc4c

3 files changed

Lines changed: 11 additions & 8 deletions

File tree

vortex-buffer/src/alignment.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ impl Alignment {
1919
/// Default alignment for device-to-host buffer copies.
2020
pub const HOST_COPY: Self = Alignment::new(256);
2121

22+
/// Default alignment for all buffers.
23+
pub const DEFAULT_ALIGNMENT: Self = Alignment::new(256);
24+
2225
/// Create a new alignment.
2326
///
2427
/// ## Panics

vortex-buffer/src/buffer.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ impl<T> Default for Buffer<T> {
4747
Self {
4848
bytes: Bytes::from_static(EMPTY_BACKING),
4949
length: 0,
50-
alignment: Alignment::of::<T>(),
50+
alignment: Alignment::DEFAULT_ALIGNMENT,
5151
_marker: PhantomData,
5252
}
5353
}
@@ -101,7 +101,7 @@ impl<T> Buffer<T> {
101101

102102
/// Create a new zeroed `Buffer` with the given value.
103103
pub fn zeroed(len: usize) -> Self {
104-
Self::zeroed_aligned(len, Alignment::of::<T>())
104+
Self::zeroed_aligned(len, Alignment::MAX)
105105
}
106106

107107
/// Create a new zeroed `Buffer` with the given value.
@@ -111,7 +111,7 @@ impl<T> Buffer<T> {
111111

112112
/// Create a new empty `ByteBuffer` with the provided alignment.
113113
pub fn empty() -> Self {
114-
Self::empty_aligned(Alignment::of::<T>())
114+
Self::empty_aligned(Alignment::DEFAULT_ALIGNMENT)
115115
}
116116

117117
/// Create a new empty `ByteBuffer` with the provided alignment.
@@ -150,7 +150,7 @@ impl<T> Buffer<T> {
150150
/// the size of `T`.
151151
pub fn from_byte_buffer(buffer: ByteBuffer) -> Self {
152152
// TODO(ngates): should this preserve the current alignment of the buffer?
153-
Self::from_byte_buffer_aligned(buffer, Alignment::of::<T>())
153+
Self::from_byte_buffer_aligned(buffer, Alignment::DEFAULT_ALIGNMENT)
154154
}
155155

156156
/// Create a `Buffer<T>` zero-copy from a `ByteBuffer`.

vortex-buffer/src/buffer_mut.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ pub struct BufferMut<T> {
3434
impl<T> BufferMut<T> {
3535
/// Create a new `BufferMut` with the requested alignment and capacity.
3636
pub fn with_capacity(capacity: usize) -> Self {
37-
Self::with_capacity_aligned(capacity, Alignment::of::<T>())
37+
Self::with_capacity_aligned(capacity, Alignment::DEFAULT_ALIGNMENT)
3838
}
3939

4040
/// Create a new `BufferMut` with the requested alignment and capacity.
@@ -60,7 +60,7 @@ impl<T> BufferMut<T> {
6060

6161
/// Create a new zeroed `BufferMut`.
6262
pub fn zeroed(len: usize) -> Self {
63-
Self::zeroed_aligned(len, Alignment::of::<T>())
63+
Self::zeroed_aligned(len, Alignment::DEFAULT_ALIGNMENT)
6464
}
6565

6666
/// Create a new zeroed `BufferMut`.
@@ -79,7 +79,7 @@ impl<T> BufferMut<T> {
7979

8080
/// Create a new empty `BufferMut` with the provided alignment.
8181
pub fn empty() -> Self {
82-
Self::empty_aligned(Alignment::of::<T>())
82+
Self::empty_aligned(Alignment::DEFAULT_ALIGNMENT)
8383
}
8484

8585
/// Create a new empty `BufferMut` with the provided alignment.
@@ -99,7 +99,7 @@ impl<T> BufferMut<T> {
9999

100100
/// Create a mutable scalar buffer by copying the contents of the slice.
101101
pub fn copy_from(other: impl AsRef<[T]>) -> Self {
102-
Self::copy_from_aligned(other, Alignment::of::<T>())
102+
Self::copy_from_aligned(other, Alignment::DEFAULT_ALIGNMENT)
103103
}
104104

105105
/// Create a mutable scalar buffer with the alignment by copying the contents of the slice.

0 commit comments

Comments
 (0)