Skip to content

Commit 1cc5af1

Browse files
committed
align frames to buffer
Signed-off-by: Alexander Droste <[email protected]>
1 parent 0bf2e55 commit 1cc5af1

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

encodings/zstd/src/array.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
use std::fmt::Debug;
55
use std::hash::Hash;
6+
use std::ops::Div;
67
use std::ops::Range;
78
use std::sync::Arc;
89

@@ -331,10 +332,6 @@ impl ZstdArray {
331332
.copied()
332333
.unwrap_or(value_bytes.len());
333334

334-
// Use slice_unaligned instead of slice to handle cases where frame boundaries
335-
// don't align with the buffer's alignment requirements (e.g., 64-byte aligned
336-
// buffers with 1-byte frame boundaries). ZSTD compression works on raw bytes
337-
// and doesn't require memory alignment.
338335
let uncompressed = &value_bytes.slice(frame_byte_starts[i]..frame_byte_end);
339336
let compressed = compressor
340337
.compress(uncompressed)
@@ -371,8 +368,14 @@ impl ZstdArray {
371368
};
372369

373370
let value_bytes = values.byte_buffer();
371+
let step_bytes = values_per_frame * byte_width;
372+
// Align frames to buffer alignment. This isnecessary for overaligned buffers.
373+
// See: https://github.com/vortex-data/vortex/issues/5715
374+
let alignment = *value_bytes.alignment();
375+
let step_width = step_bytes.div_ceil(alignment) * alignment;
376+
374377
let frame_byte_starts = (0..n_values * byte_width)
375-
.step_by(values_per_frame * byte_width)
378+
.step_by(step_width)
376379
.collect::<Vec<_>>();
377380
let Frames {
378381
dictionary,

encodings/zstd/src/test.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,6 @@ fn test_sliced_array_children() {
207207
#[test]
208208
fn test_zstd_alignment_issue() {
209209
// Scenario where a u8 array has a 64-byte alignment.
210-
// See: https://github.com/vortex-data/vortex/issues/5715
211210
let data = vec![0u8; 2];
212211

213212
let aligned_buffer = Buffer::copy_from_aligned(&data, Alignment::new(8));

0 commit comments

Comments
 (0)