perf(index): accelerate RQ scale search - #8924
Merged
Merged
Conversation
BubbleCal
marked this pull request as ready for review
September 1, 2026 11:18
Contributor
There was a problem hiding this comment.
The equal-threshold correctness issue is fixed: duplicate keys now reproduce the prior comparison-sort behavior, while unique keys retain the radix path. The remaining risk is that the benchmark predates this fallback; duplicate-heavy inputs perform both sorting paths and use additional temporary memory, so the target-workload speedup is not yet demonstrated on this head.
Xuanwo
approved these changes
Sep 1, 2026
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.
What is the performance issue?
RQ scale search generates several quantization thresholds per vector dimension and sorts them before selecting the best rescale factor. For RQ8 on 1,536-dimensional vectors, comparison-based tuple sorting was the dominant sampled cost in this part of index training.
How does this PR improve performance?
This PR packs each
(positive finite f32 threshold, dimension index)pair into au64and sorts the threshold bits with four stable byte-wise radix passes. Positive finite IEEE-754 values have the same ordering as their bit patterns, so this removes comparison-heavy tuple sorting for the common unique-key case. Equal thresholds retain the previous quantizer behavior by falling back to the original comparison sort because their event order can affect the incrementally evaluated floating-point objective.The implementation is isolated from the shuffle reader and scheduling changes in #8894.
Benchmark
The following supporting A/B measurement isolated this implementation on the #8894 benchmark context. Both variants ran on the same AWS
m7i.4xlargeVM (16 vCPU, 64 GiB RAM, gp3 storage) against the same S3 dataset: 1,000,000 rows, 1,536float32dimensions, 10,000 supplied IVF centroids, and RQ8. Each value is from one fresh process.c7508ad49)174663d0a)The two measured commits differed only by the initial RQ radix implementation, but they were on the stacked #8894 context and predate the equal-threshold comparison-sort fallback in this standalone latest-
mainPR. The standalone head has not been remeasured, so the table is supporting implementation evidence rather than a current-head benchmark claim.Testing
cargo test -p lance-index vector::bq::builder::tests --lib --no-fail-fast(13 passed)cargo fmt --all -- --checkcargo clippy --all --tests --benches -- -D warningsThe added regression tests verify that radix sorting matches floating-point threshold ordering and that the selected rescale factor is bit-for-bit identical to the comparison-sort reference for RQ1 through RQ8, including zero, duplicate, NaN, and infinite inputs. A targeted equal-threshold regression also verifies the exact rescale factor from the previous comparison-sort behavior.