-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Just a small one for y'all. `vortex-buffer/src/lib.rs` is a decent starting point for this change. This PR introduces `Buffer<T>` and `BufferMut<T>` for as (im)mutable zero-copy runtime-aligned buffers. You can think of `BufferMut` as a `Vec`, but every time it re-allocates to resize, it ensures the new buffer remains aligned as requested. This is neat. Unlike `Vec<T>`, it allows you to build buffers with much larger alignment, for example always 128 bytes for FastLanes, or 4096/8192 for page-aligned buffers. ## Limitation: no zero-copy from `Vec<T>` The implementation essentially wraps `Bytes` and `BytesMut` to provide this functionality. As a result, there is one major annoying limitation: we cannot go from `Vec<T>` to `Buffer<T>` *and back to* `Vec<T>` with zero-copy. `Bytes::from_owner` is able to take an externally allocated buffer (i.e. `Vec<T>`), but it will not return it back to you. I've decided to entirely disallow going from `Vec<T>` to `Buffer<T>` to avoid this odd performance foot-gun. Although in doing this, I _force_ a copy `Buffer::<T>::copy_from_vec`... whereas if we _did_ allow conversion from `Vec<T>` then we would only pay for the copy if we tried to turn it into a `BufferMut<T>`. So.... not sure. We can see an example of this when encoding ALP arrays. The result our library returns is a `Vec<T>`. So we are forced to copy. One way around this is to allow zero-copy into `Buffer<T>`, the other way is to make the ALP library generic over `V: Default + Extend<T>` to allow the library to initialize and append to a collection of elements in some arbitrary container type. Perhaps an argument for allowing `From<Vec<T>>` is that we would rarely benefit from `into_mut` for arrays constructed by hand by users in-memory (in-memory arrays constructed by _us_ should use `Buffer<T>`). And any arrays loaded from disk, would be loaded into a `Buffer<T>`... ## Wire Break This PR adds an `alignment: u16` field to every flatbuffer Array's buffers. This lets us know the desired alignment for a given buffer deep within the I/O stack, helping to avoid copies later on. --------- Co-authored-by: Will Manning <[email protected]>
- Loading branch information
1 parent
5a32b5a
commit 920b2d2
Showing
208 changed files
with
4,533 additions
and
2,468 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.