Skip to content
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

perf: PQ transform re-allocates a lot #2837

Closed
wjones127 opened this issue Sep 5, 2024 · 1 comment · Fixed by #3399
Closed

perf: PQ transform re-allocates a lot #2837

wjones127 opened this issue Sep 5, 2024 · 1 comment · Fixed by #3399
Labels
good first issue Good for newcomers performance rust Rust related tasks

Comments

@wjones127
Copy link
Contributor

Using flat_map here breaks the size_hint() chain, preventing collect() from creating a perfectly sized allocation up front. Even though we should in theory know the exact size of the output.

.flat_map(|vector| {
vector
.chunks_exact(sub_dim)
.enumerate()
.map(|(sub_idx, sub_vector)| {
let centroids = get_sub_vector_centroids(
codebook.values(),
dim,
num_bits,
num_sub_vectors,
sub_idx,
);
compute_partition(centroids, sub_vector, distance_type).map(|v| v as u8)
})
.collect::<Vec<_>>()
})
.collect::<Vec<_>>();

I noticed this while doing a benchmark with bytehound and sorting by number of allocations.

@wjones127 wjones127 added performance good first issue Good for newcomers rust Rust related tasks labels Sep 5, 2024
@wjones127
Copy link
Contributor Author

These instructions for benchmarking are also relevant for this issue: #2838 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers performance rust Rust related tasks
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant