You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "Rich-T-kid (via GitHub)" <gi...@apache.org> on 2026/08/26 18:34:42 UTC

[I] Introduce an alignment-guaranteeing Vec wrapper for use in buffer-building optimizations [arrow-rs]

Rich-T-kid opened a new issue, #10868:
URL: https://github.com/apache/arrow-rs/issues/10868

   ### Is your feature request related to a problem or challenge?
   
   Several performance optimizations in arrow-rs (e.g. #10812, take on List<T>) would naturally reach for Vec<u8> or Vec<T>, Rust's stdlib Vec is heavily optimized by the compiler and benefits from inlining, LLVM vectorization hints, and well-understood growth patterns. However, any buffer that will be reinterpreted as a typed `ScalarBuffer<T>` must satisfy T's alignment requirement. `Vec<u8>` only guarantees 1-byte alignment, causing panics like Memory pointer is not aligned with the specified scalar type
   
   ### Describe the solution you'd like
   
   Introduce a thin newtype in arrow-buffer along the lines of:
   
   ```
   #[repr(align(64))]
   struct Align64([u8; 64]);
   
   
   pub struct AlignedVec(Vec<Align64>);
   
   ```
   
   that exposes a Vec-compatible interface (push, extend_from_slice, len, as_slice, etc.) while guaranteeing 64-byte alignment. This would let optimization hot paths use idiomatic Vec patterns and get full compiler/LLVM optimization benefits without sacrificing Arrow's alignment invariants.
   
   *this would surely need more work than this, but just a loose idea*
   
   ### Describe alternatives you've considered
   
   sticking with MutableBuffer
   
   ### Additional context
   
   this has been a common issue I've encountered when trying to optimize portions of the code base. #10812 recently occurred where switching from `Vec<u8>` to MutableBuffer caused a [30% regression](https://github.com/apache/arrow-rs/pull/10812#issuecomment-5429213753)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Introduce an alignment-guaranteeing Vec wrapper for use in buffer-building optimizations [arrow-rs]

Posted by "Rich-T-kid (via GitHub)" <gi...@apache.org>.
Rich-T-kid commented on issue #10868:
URL: https://github.com/apache/arrow-rs/issues/10868#issuecomment-5753212734

   Would be nice to have a a list of possible drop in replacements for this. will do that before opening the PR so its easier


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Introduce an alignment-guaranteeing Vec wrapper for use in buffer-building optimizations [arrow-rs]

Posted by "Rich-T-kid (via GitHub)" <gi...@apache.org>.
Rich-T-kid commented on issue #10868:
URL: https://github.com/apache/arrow-rs/issues/10868#issuecomment-5766296155

   ## `MutableBuffer` → `Vec<T>` Drop-in Replacement Candidates
   
   Scanned the codebase for write-heavy `MutableBuffer` usage where the only methods called (`push`, `extend_from_slice`, `resize`, `clear`, `from_len_zeroed`) have direct `Vec<T>` equivalents. Organized by crate and file below.
   
   ---
   
   ### `arrow-arith`
   
   | File | Lines | Methods Used | Replacement |
   |------|-------|-------------|-------------|
   | `src/arity.rs` | 393 | `new` + `push_unchecked` loop | `Vec<O::Native>` |
   
   ---
   
   ### `arrow-data`
   
   | File | Lines | Methods Used | Replacement |
   |------|-------|-------------|-------------|
   | `src/data.rs` | 101, 107, 118, 128 | `new` + `push` | `Vec<i32>` / `Vec<i64>` |
   | `src/transform/mod.rs` | 355 | `new` + `push` | `Vec<Offset>` |
   
   ---
   
   ### `arrow-ipc`
   
   | File | Lines | Methods Used | Replacement |
   |------|-------|-------------|-------------|
   | `src/reader.rs` | 960, 1887 | `try_from_len_zeroed` + `as_slice_mut` + `read_exact` / `try_resize` | `Vec<u8>` |
   | `src/reader.rs` | 3371, 3414, 3493 | `with_capacity` + `push(0_u8)` + `extend_from_slice` | `Vec<u8>` |
   | `src/writer.rs` | 2284, 2300 | `new` + `extend_from_slice` | `Vec<u8>` |
   
   ---
   
   ### `arrow-ord`
   
   | File | Lines | Methods Used | Replacement |
   |------|-------|-------------|-------------|
   | `src/comparison.rs` | 51, 92 | `try_from_len_zeroed` + `as_slice_mut` + `set_bit` | `Vec<u8>` |
   
   ---
   
   ### `arrow-row`
   
   | File | Lines | Methods Used | Replacement |
   |------|-------|-------------|-------------|
   | `src/fixed.rs` | 367, 368 | `new` + `push` loop | `Vec<u64>` |
   | `src/fixed.rs` | 457 | `new` + `extend_from_slice` loop + `as_slice_mut` | `Vec<u8>` |
   | `src/variable.rs` | 289 | `new` + `extend_from_slice` loop + `as_slice_mut` | `Vec<u8>` |
   | `src/variable.rs` | 332 | `new` + `extend_from_slice` loop + `get_unchecked_mut` | `Vec<u8>` |
   
   ---
   
   ### `arrow-select`
   
   | File | Lines | Methods Used | Replacement |
   |------|-------|-------------|-------------|
   | `src/concat.rs` | 310 | `with_capacity` + `push` loop | `Vec<OffsetSize>` |
   | `src/filter.rs` | 986, 995 | `with_capacity` + `extend_from_slice` loop | `Vec<u8>` |
   | `src/filter.rs` | 956 | `with_capacity` + `as_mut_ptr` + `ptr::copy_nonoverlapping` + `set_len` | `Vec<u8>` (unsafe, needs care) |
   | `src/interleave.rs` | 408 | `from_len_zeroed` + `as_slice_mut` + `set_bit` | `Vec<u8>` |
   | `src/take.rs` | 936 | `new` + `extend_from_slice` loop | `Vec<u8>` |
   | `src/take.rs` | 1156 | `from_len_zeroed` + `as_slice_mut` + `copy_from_slice` | `Vec<u8>` |
   | `src/zip.rs` | 542, 567, 607, 833 | `with_capacity` + `try_repeat_slice_n_times` | needs `try_repeat_slice_n_times` on `Vec` — not a clean drop-in |
   
   ---
   
   ### `arrow-string`
   
   | File | Lines | Methods Used | Replacement |
   |------|-------|-------------|-------------|
   | `src/concat_elements.rs` | 232 | `with_capacity` + `clear` + `try_extend_from_slice` x2 (reused temp buf) | `Vec<u8>` |
   | `src/substring.rs` | 375, 427 | `new` + `try_extend_from_slice` loop | `Vec<u8>` |
   
   ---
   
   **Notes:**
   - `src/zip.rs` sites use `try_repeat_slice_n_times`, which is a `MutableBuffer`-specific method with no `Vec` equivalent — skip or add a helper.
   - `src/filter.rs:956` uses raw pointer writes (`as_mut_ptr` + `copy_nonoverlapping` + `set_len`) — replaceable with `Vec<u8>` but requires the same unsafe block.
   - Everything else is a straightforward mechanical swap.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Introduce an alignment-guaranteeing Vec wrapper for use in buffer-building optimizations [arrow-rs]

Posted by "Rich-T-kid (via GitHub)" <gi...@apache.org>.
Rich-T-kid commented on issue #10868:
URL: https://github.com/apache/arrow-rs/issues/10868#issuecomment-5771419006

   will start working on this over the weekend 👍 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Introduce an alignment-guaranteeing Vec wrapper for use in buffer-building optimizations [arrow-rs]

Posted by "Rich-T-kid (via GitHub)" <gi...@apache.org>.
Rich-T-kid closed issue #10868: Introduce an alignment-guaranteeing Vec wrapper for use in buffer-building optimizations
URL: https://github.com/apache/arrow-rs/issues/10868


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org