perf: speed up PQ distance lookup#7659
Draft
ddupg wants to merge 1 commit into
Draft
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
PQDistCalculator::distanceby indexing transposed PQ codes directly instead of rebuilding an iterator withskip(id).step_by(num_vectors)for each candidate.Benchmark
Benchmark command:
Focused before/after Criterion comparison with the same benchmark code:
6c291ab14555d327dda61860433034bce7586bd7:1.1122 msmedian estimate per 16,384 distance calls, interval[1.0965 ms, 1.1290 ms]1.0085 msmedian estimate per 16,384 distance calls, interval[1.0005 ms, 1.0168 ms][−10.390%, −9.3597%, −8.3427%],p = 0.00 < 0.05The benchmark uses 8-bit PQ with
dim=512,num_sub_vectors=64,total=65,536, and deterministic seeds.Validation
cargo fmt --all cargo test -p lance-index vector::pq::storage -- --nocapture cargo clippy -p lance-index --bench pq_distance_lookup -- -D warnings cargo bench -p lance-index --bench pq_distance_lookup -- --warm-up-time 3 --measurement-time 10