jerry-024 commented on code in PR #99:
URL: 
https://github.com/apache/paimon-vector-index/pull/99#discussion_r4001829795


##########
core/src/distance.rs:
##########
@@ -173,6 +253,25 @@ fn fvec_l2sqr_scalar(a: &[f32], b: &[f32]) -> f32 {
     sum
 }
 
+/// Mirrors [`fvec_l2sqr_scalar`] term for term, so the value it returns on
+/// completion is the one that function would have produced.
+#[cfg(any(
+    target_arch = "x86_64",
+    not(any(target_arch = "x86_64", target_arch = "aarch64"))
+))]
+#[inline]
+fn fvec_l2sqr_unless_exceeds_scalar(a: &[f32], b: &[f32], threshold: f32) -> 
Option<f32> {
+    let mut sum = 0.0f32;
+    for i in 0..a.len() {
+        let d = a[i] - b[i];
+        sum += d * d;
+        if sum > threshold {

Review Comment:
   [Minor] Match the scalar cutoff probe cadence to SIMD
   
   This fallback checks `sum > threshold` after every coordinate, adding a 
compare and branch to the hot loop even though the SIMD kernels deliberately 
probe only every `L2_PROBE_STRIDE` elements. It is used on x86_64 hosts without 
AVX2 and on architectures without a dedicated SIMD implementation. Please probe 
at stride boundaries and once after the loop, as the AVX2/NEON paths do; L2 
partial sums are monotonic, so this preserves correctness while avoiding the 
per-element branch.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to