-
Notifications
You must be signed in to change notification settings - Fork 544
chore: add utilities to LanceBuffer #2784
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
broccoliSpicy
merged 8 commits into
lance-format:main
from
westonpace:chore/add-buffer-utils
Aug 26, 2024
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
dc878c3
Add various utilities to LanceBuffer
westonpace 6332bbd
Add some tests
westonpace 0bfb6ce
Specify hex crate version
westonpace d12a3f6
Minor change to as_hex
westonpace c59150e
Apply clippy suggestions
westonpace 951ed90
Address review comments
westonpace 6cfa12b
Move From sized slice to copy_slice
westonpace 46e2a8a
Merge branch 'main' into chore/add-buffer-utils
broccoliSpicy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // SPDX-FileCopyrightText: Copyright The Lance Authors | ||
|
|
||
| use criterion::{black_box, criterion_group, criterion_main, Criterion, Throughput}; | ||
| use lance_encoding::buffer::LanceBuffer; | ||
|
|
||
| const NUM_VALUES: &[usize] = &[1024 * 1024, 32 * 1024, 8 * 1024]; | ||
|
|
||
| fn bench_zip(c: &mut Criterion) { | ||
| for num_values in NUM_VALUES { | ||
| let num_values = *num_values; | ||
| let mut group = c.benchmark_group(&format!("zip_{}Ki", num_values / 1024)); | ||
|
|
||
| group.throughput(Throughput::Bytes((num_values * 6) as u64)); | ||
|
|
||
| group.bench_function("2_4_zip_into_6", move |b| { | ||
| // Zip together a 2-byte-per-buffer and an 8-byte-per-buffer array, each with 1Mi items | ||
| let random_shorts: Vec<u8> = | ||
| (0..num_values * 2).map(|_| rand::random::<u8>()).collect(); | ||
| let random_ints: Vec<u8> = (0..num_values * 4).map(|_| rand::random::<u8>()).collect(); | ||
| let mut buffers = vec![ | ||
| (LanceBuffer::Owned(random_shorts), 16), | ||
| (LanceBuffer::Owned(random_ints), 32), | ||
| ]; | ||
| let buffers = &mut buffers; | ||
|
|
||
| b.iter(move || { | ||
| let buffers = buffers | ||
| .iter_mut() | ||
| .map(|(buf, bits_per_value)| (buf.borrow_and_clone(), *bits_per_value)) | ||
| .collect::<Vec<_>>(); | ||
| black_box(LanceBuffer::zip_into_one(buffers, num_values as u64).unwrap()); | ||
| }) | ||
| }); | ||
|
|
||
| group.bench_function("2_2_2_zip_into_6", move |b| { | ||
| // Zip together a 2-byte-per-buffer and an 8-byte-per-buffer array, each with 1Mi items | ||
| let random_shorts1: Vec<u8> = | ||
| (0..num_values * 2).map(|_| rand::random::<u8>()).collect(); | ||
| let random_shorts2: Vec<u8> = | ||
| (0..num_values * 2).map(|_| rand::random::<u8>()).collect(); | ||
| let random_shorts3: Vec<u8> = | ||
| (0..num_values * 2).map(|_| rand::random::<u8>()).collect(); | ||
| let mut buffers = vec![ | ||
| (LanceBuffer::Owned(random_shorts1), 16), | ||
| (LanceBuffer::Owned(random_shorts2), 16), | ||
| (LanceBuffer::Owned(random_shorts3), 16), | ||
| ]; | ||
| let buffers = &mut buffers; | ||
|
|
||
| b.iter(move || { | ||
| let buffers = buffers | ||
| .iter_mut() | ||
| .map(|(buf, bits_per_value)| (buf.borrow_and_clone(), *bits_per_value)) | ||
| .collect::<Vec<_>>(); | ||
| black_box(LanceBuffer::zip_into_one(buffers, num_values as u64).unwrap()); | ||
| }) | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| #[cfg(target_os = "linux")] | ||
| criterion_group!( | ||
| name=benches; | ||
| config = Criterion::default().significance_level(0.1).sample_size(10) | ||
| .with_profiler(pprof::criterion::PProfProfiler::new(100, pprof::criterion::Output::Flamegraph(None))); | ||
| targets = bench_zip); | ||
| criterion_main!(benches); |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.