Skip to content

Commit

Permalink
feat: consume right_parts buffer in alp-rd decompression (#1785)
Browse files Browse the repository at this point in the history
This slightly improves decompression throughput for larger arrays.
Passing in an owned buffer is insufficient, (see the benchmarks for
"passing a BufferMut"), we must actually mutate the array in-place.

develop
```
alp_compress       fastest       │ slowest       │ median        │ mean          │ samples │ iters
╰─ decompress_rd                 │               │               │               │         │
   ├─ f32                        │               │               │               │         │
   │  ├─ 100000    59.62 µs      │ 171.8 µs      │ 65.7 µs       │ 65.89 µs      │ 100     │ 100
   │  ├─ 1000000   747.4 µs      │ 1.116 ms      │ 788.4 µs      │ 809.7 µs      │ 100     │ 100
   │  ╰─ 10000000  9.708 ms      │ 14.55 ms      │ 9.948 ms      │ 10.05 ms      │ 100     │ 100
   ╰─ f64                        │               │               │               │         │
      ├─ 100000    67.24 µs      │ 137.2 µs      │ 67.49 µs      │ 69.21 µs      │ 100     │ 100
      ├─ 1000000   1.168 ms      │ 1.906 ms      │ 1.272 ms      │ 1.337 ms      │ 100     │ 100
      ╰─ 10000000  18.65 ms      │ 23.48 ms      │ 19.24 ms      │ 19.8 ms       │ 100     │ 100
```
passing a BufferMut
```
alp_compress       fastest       │ slowest       │ median        │ mean          │ samples │ iters
╰─ decompress_rd                 │               │               │               │         │
   ├─ f32                        │               │               │               │         │
   │  ├─ 100000    60.16 µs      │ 94.2 µs       │ 66.81 µs      │ 68.19 µs      │ 100     │ 100
   │  ├─ 1000000   738.8 µs      │ 1.189 ms      │ 765.6 µs      │ 793.3 µs      │ 100     │ 100
   │  ╰─ 10000000  9.681 ms      │ 10.89 ms      │ 9.822 ms      │ 9.869 ms      │ 100     │ 100
   ╰─ f64                        │               │               │               │         │
      ├─ 100000    67.54 µs      │ 109.9 µs      │ 77.41 µs      │ 79.14 µs      │ 100     │ 100
      ├─ 1000000   1.209 ms      │ 1.804 ms      │ 1.293 ms      │ 1.328 ms      │ 100     │ 100
      ╰─ 10000000  18.58 ms      │ 25.08 ms      │ 19.87 ms      │ 20.22 ms      │ 100     │ 100
```
using for_each_with_index
```
alp_compress       fastest       │ slowest       │ median        │ mean          │ samples │ iters
╰─ decompress_rd                 │               │               │               │         │
   ├─ f32                        │               │               │               │         │
   │  ├─ 100000    46.62 µs      │ 163.3 µs      │ 50.16 µs      │ 50.75 µs      │ 100     │ 100
   │  ├─ 1000000   628.6 µs      │ 828.2 µs      │ 675.2 µs      │ 688.2 µs      │ 100     │ 100
   │  ╰─ 10000000  8.016 ms      │ 9.968 ms      │ 8.114 ms      │ 8.175 ms      │ 100     │ 100
   ╰─ f64                        │               │               │               │         │
      ├─ 100000    63.87 µs      │ 86.29 µs      │ 68.66 µs      │ 68.3 µs       │ 100     │ 100
      ├─ 1000000   934.4 µs      │ 2.173 ms      │ 1.085 ms      │ 1.09 ms       │ 100     │ 100
      ╰─ 10000000  14.18 ms      │ 17.89 ms      │ 14.52 ms      │ 14.78 ms      │ 100     │ 100
```
  • Loading branch information
danking authored Jan 2, 2025
1 parent 570624e commit b44656c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
4 changes: 2 additions & 2 deletions encodings/alp/src/alp_rd/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ impl IntoCanonical for ALPRDArray {
left_parts.into_buffer::<u16>(),
left_parts_dict,
self.metadata().right_bit_width,
right_parts.into_buffer::<u32>(),
right_parts.into_buffer_mut::<u32>(),
self.left_parts_patches(),
)?,
self.logical_validity().into_validity(),
Expand All @@ -215,7 +215,7 @@ impl IntoCanonical for ALPRDArray {
left_parts.into_buffer::<u16>(),
left_parts_dict,
self.metadata().right_bit_width,
right_parts.into_buffer::<u64>(),
right_parts.into_buffer_mut::<u64>(),
self.left_parts_patches(),
)?,
self.logical_validity().into_validity(),
Expand Down
18 changes: 10 additions & 8 deletions encodings/alp/src/alp_rd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ pub fn alp_rd_decode<T: ALPRDFloat>(
left_parts: Buffer<u16>,
left_parts_dict: &[u16],
right_bit_width: u8,
right_parts: Buffer<T::UINT>,
right_parts: BufferMut<T::UINT>,
left_parts_patches: Option<Patches>,
) -> VortexResult<Buffer<T>> {
if left_parts.len() != right_parts.len() {
Expand Down Expand Up @@ -288,13 +288,15 @@ pub fn alp_rd_decode<T: ALPRDFloat>(
}

// Shift the left-parts and add in the right-parts.
Ok(
BufferMut::<T>::from_iter(values.iter().zip(right_parts.iter()).map(|(left, right)| {
let left = <T as ALPRDFloat>::from_u16(*left);
T::from_bits((left << (right_bit_width as usize)) | *right)
}))
.freeze(),
)
let mut index = 0;
Ok(right_parts
.map_each(|right| {
let left = values[index];
index += 1;
let left = <T as ALPRDFloat>::from_u16(left);
T::from_bits((left << (right_bit_width as usize)) | right)
})
.freeze())
}

/// Find the best "cut point" for a set of floating point values such that we can
Expand Down

0 comments on commit b44656c

Please sign in to comment.